|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Sed Command Help (Introductory Level Question)
I have a file with the format:
John Adams 55 George Bull 77 Anne Blue 99 basically there is a first name then 1 or more spaces then the last name then 1 or more spaces and the age. I need to rewrite the file so the format looks like this: Adams, John 55 Bull, George 77 Blue, Anne 99 last name, first name age (only one space between each). I have to use the sed command and I'm trying to do it with the substituion option and I can't get it to work. It must be a one-line command and you can't use awk. The file name is sed1.data that I'm reading from and writing the new format to. Please help me, I appreciate it! |
|
#2
|
|||
|
|||
|
Quote:
I know I need to store the first name in tag#1, store the last name in tag#2 and the age in tag#3 then just send tag#2 add a comma and a space then tag #1 then another space and finally tag#3 back to the original file but everything I've tried hasn't worked. |
|
#3
|
|||
|
|||
|
replace 'S+T' by a litterally space followed by a tab character
this exactly match your exemple: s/\([A-Z][a-z]*\)[S+T]*[S+T]\([A-Z][a-z]*\)[S+T]*[S+T]\([0-9][0-9]*\)/\2, \1 \3/ quick+dirty, you can use: s/\(.*\)[S+T]*[S+T]\(.*\)[S+T]*[S+T]\(.*\)/\2, \1 \3/ |
|
#4
|
|||
|
|||
|
Thanks guggach. I was so close but I didn't have the space+tab in there to separate the 3 different fields, which explains why I was just taking the whole line. I have a similar question now that I'm trying to figure out on my own based on the help you gave me. This time I want to take only two fields and they are separated by spaces/tabs but also test.
Ex: (output of the who command) z080069 pts/1 Sep 8 09:25 (euclid) I need to take the first field (login ID) and the login time and separate them with a space. For the example above the output should look like: z080069 09:25 Right now I'm doing this and getting the login ID and the time, but also the last field (which I don't want/need): who | sed 's/^\([a-z0-9]*\)[S+T]*.*[S+T]*.*[S+T]*.*[S+T]*[S+T]\(..:..\) /\1 \2/' How do I go to the next line after getting the login time? |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Sed Command Help (Introductory Level Question) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|