Skip to main content
deleted 18 characters in body
Source Link
dovah
  • 1.8k
  • 7
  • 24
  • 41

I'd like to replace all the newlines after a line containing a given pattern with a tab.

Input file:

$ cat File1
NAME1
NAME1_infoN1_info
NAME2
NAME2_infoN2_info 

I'm creating some flags at the ends of the future "tab"s:

sed '/^NAME/s/$/\*/g; /^NAME/!{s/^/+/g}' File1.txt > File2.txt

$ cat File2
NAME1*
+NAME1_info+N1_info
NAME2*
+NAME2_info+N2_info

Then I'm removing the characters between the "flags" in order to obtain the wished output. I tried two sed patterns (but none of them change my 'File2'):

head File2 | sed -e 's/\(\*\).*\(+\)/\1\t\2/g'
head File2 | sed -n '/\*/,/+/p'

This is the what the output should look like:

$ cat File3
NAME1   NAME1_infoN1_info
NAME2   NAME2_infoN2_info 

I'd like to replace all the newlines after a line containing a given pattern with a tab.

Input file:

$ cat File1
NAME1
NAME1_info
NAME2
NAME2_info 

I'm creating some flags at the ends of the future "tab"s:

sed '/^NAME/s/$/\*/g; /^NAME/!{s/^/+/g}' File1.txt > File2.txt

$ cat File2
NAME1*
+NAME1_info
NAME2*
+NAME2_info

Then I'm removing the characters between the "flags" in order to obtain the wished output. I tried two sed patterns (but none of them change my 'File2'):

head File2 | sed -e 's/\(\*\).*\(+\)/\1\t\2/g'
head File2 | sed -n '/\*/,/+/p'

This is the what the output should look like:

$ cat File3
NAME1   NAME1_info
NAME2   NAME2_info 

I'd like to replace all the newlines after a line containing a given pattern with a tab.

Input file:

$ cat File1
NAME1
N1_info
NAME2
N2_info 

I'm creating some flags at the ends of the future "tab"s:

sed '/^NAME/s/$/\*/g; /^NAME/!{s/^/+/g}' File1.txt > File2.txt

$ cat File2
NAME1*
+N1_info
NAME2*
+N2_info

Then I'm removing the characters between the "flags" in order to obtain the wished output. I tried two sed patterns (but none of them change my 'File2'):

head File2 | sed -e 's/\(\*\).*\(+\)/\1\t\2/g'
head File2 | sed -n '/\*/,/+/p'

This is the what the output should look like:

$ cat File3
NAME1   N1_info
NAME2   N2_info 
Source Link
dovah
  • 1.8k
  • 7
  • 24
  • 41

Using sed to replace characters between two patterns

I'd like to replace all the newlines after a line containing a given pattern with a tab.

Input file:

$ cat File1
NAME1
NAME1_info
NAME2
NAME2_info 

I'm creating some flags at the ends of the future "tab"s:

sed '/^NAME/s/$/\*/g; /^NAME/!{s/^/+/g}' File1.txt > File2.txt

$ cat File2
NAME1*
+NAME1_info
NAME2*
+NAME2_info

Then I'm removing the characters between the "flags" in order to obtain the wished output. I tried two sed patterns (but none of them change my 'File2'):

head File2 | sed -e 's/\(\*\).*\(+\)/\1\t\2/g'
head File2 | sed -n '/\*/,/+/p'

This is the what the output should look like:

$ cat File3
NAME1   NAME1_info
NAME2   NAME2_info