![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replacing the last data of each line ina file | jisha | Shell Programming and Scripting | 6 | 2 Weeks Ago 04:47 AM |
| How to combine text data into one line? | rcky_mntere | Shell Programming and Scripting | 2 | 05-02-2008 10:48 AM |
| get data from next line | whamchaxed | UNIX for Dummies Questions & Answers | 5 | 12-04-2007 03:27 PM |
| add data from command line to end of file | bryan | UNIX for Dummies Questions & Answers | 3 | 05-23-2006 03:57 PM |
| Extracting data from each line | csaha | Shell Programming and Scripting | 1 | 04-26-2006 08:49 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Cut data and put it in next line
here is my sample file
dn: cn=Anandmohan Singh,ou=addressbook,dc=thbs,dc=com objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson cn: Anandmohan Singh givenName: Anandmohan mail: anand_ms@thbs.com mobile: 9986010455 ou: null physicalDeliveryOfficeName: ST-6th Floor sn: Singh telephoneNumber: 41827200 Extn: 7400 title: Associate Software Engineer - Trainee uid: 1432 dn: cn=Riteshkumar Mohanty,ou=addressbook,dc=thbs,dc=com objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson cn: Riteshkumar Mohanty givenName: Riteshkumar mail: ritesh_m@thbs.com mobile: 9916953109 ou: null physicalDeliveryOfficeName: ST-6th Floor sn: Mohanty telephoneNumber: 41827200 Extn: 7400 title: Associate Software Engineer - Trainee uid: 1418 i want to cut the ext from the line where telephone number is given and put it in next line,something like this-- dn: cn=Anandmohan Singh,ou=addressbook,dc=thbs,dc=com objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson cn: Anandmohan Singh givenName: Anandmohan mail: anand_ms@thbs.com mobile: 9986010455 ou: null physicalDeliveryOfficeName: ST-6th Floor sn: Singh telephoneNumber: 41827200 Extn: 7400 title: Associate Software Engineer - Trainee uid: 1432 dn: cn=Riteshkumar Mohanty,ou=addressbook,dc=thbs,dc=com objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetOrgPerson cn: Riteshkumar Mohanty givenName: Riteshkumar mail: ritesh_m@thbs.com mobile: 9916953109 ou: null physicalDeliveryOfficeName: ST-6th Floor sn: Mohanty telephoneNumber: 41827200 Extn: 7401 title: Associate Software Engineer - Trainee uid: 1418 |
| Forum Sponsor | ||
|
|
|
|||
|
If you put your file content in a file called "hi.txt" then his is the command to obtain what you required:
[ramki@lindesk3 ramki]$ cat hi.txt | grep -i "ext" telephoneNumber: 41827200 Extn: 7400 [ramki@lindesk3 ramki]$ cat hi.txt | grep -i "ext" | sed 's/ Extn/\nExtn/g' telephoneNumber: 41827200 Extn: 7400 Thanks, Ramkrix Last edited by ramkrix; 03-23-2008 at 09:59 PM. |
|
|||
|
heres a guideline of what i think needs to be done.
have input file hi.txt and outputfile hi2.txt read each line of input file and output to new file. on each line do an awk: eg. cat hi.txt | awk '{print $1 " " $2 " " $3 " " $4 } ' telephone: 345345435 Extn: 4545 now u have four fields seperate. then when $1 = "telephone:" output $1 and $2 then next line output $3 and $4. and at the eof mv hi2.txt to hi.txt |