![]() |
|
|
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 |
| Merging lines - Tuning the script | senthil_is | Shell Programming and Scripting | 3 | 03-05-2008 03:24 AM |
| Merging files with AWK filtering and counting lines | Meert | Shell Programming and Scripting | 2 | 01-28-2008 11:58 AM |
| merging two lines in a file | thaduka | UNIX for Dummies Questions & Answers | 6 | 07-11-2007 10:27 AM |
| How to count lines - ignoring blank lines and commented lines | kthatch | UNIX for Dummies Questions & Answers | 6 | 05-25-2007 02:21 AM |
| Merging lines into one | Foxgard | UNIX for Dummies Questions & Answers | 8 | 06-19-2005 07:36 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Merging lines using AWK
Hi,
Anybody help on this. ![]() I want to merge the line with previous line, if the line starts with 7. Otherwise No change in the line. Example file aa.txt is like below 122122 222222 333333 734834 702923 389898 790909 712345 999999 My output should be written in another file called bb.txt 122122 222222 333333734834702923 389898790909712345 999999 Your help is very much appriciated. Last edited by senthil_is; 03-04-2008 at 11:19 PM.. Reason: change |
|
||||
Thanks summer.The output is coming with one blank line in the header. # Here blank line is coming. 122122 222222 333333734834702923 389898790909712345 999999 How to avoid and how to redirect to another file. |
|
||||
|
Quote:
Code:
[n]awk '{
if ($0 ~ /^7/)
l = l" "$0
else {
if (l) print l
l = $0
}
} END {if (l) print l}' aa.txt > bb.txt
|
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|