![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Append line that does not contain pipe to it previous line | ainuddin | Shell Programming and Scripting | 11 | 11-11-2008 10:58 AM |
| Appending line number to each line and getting total number of lines | chiru_h | Shell Programming and Scripting | 2 | 03-25-2008 10:19 AM |
| Appending a line in a file after a particular line | maxvirrozeito | Shell Programming and Scripting | 7 | 12-12-2007 01:58 PM |
| Appending line ending with '}" to new line | aismann | Shell Programming and Scripting | 4 | 08-13-2007 03:09 AM |
| Appending the line number and a seperator to each line of a file ? | pjcwhite | Shell Programming and Scripting | 4 | 03-21-2007 01:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
sed: appending alternate line after previous line
Hi all,
I have to append every alternate line after its previous line. For example if my file has following contents line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts Required output should be line1: unix is an OS it is open source line 2: it supports shell programming we can write shell scripts I think this could be done using sed, but how could i do this please help? If it cant be done using sed then please suggest other methods |
|
||||
|
zaxxon's solution is the best one...
Without using sed i tried like this ( its a lengthy code ) #!/bin/bash Count=0 while read line do echo $line >> output.txt Count=`expr $Count + 1` if [ $Count -eq 2 ] then { awk -v RS='' '{gsub("\n", FS)}1' output.txt >> new.txt :>output.txt Count=0 } fi done < testfile.txt rm -rf output.txt --------output---------- line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|