![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum 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 |
| Avoid creating temporary files on editing a file in Ubuntu | royalibrahim | Linux | 7 | 11-17-2007 02:57 AM |
| searching for content of files | Aretai | UNIX for Dummies Questions & Answers | 19 | 03-09-2007 03:44 AM |
| Cleaning the content of log files | jyotipg | Shell Programming and Scripting | 1 | 11-14-2006 11:19 PM |
| content need changes- many files | swchee | Shell Programming and Scripting | 3 | 10-05-2006 09:29 AM |
| Compare the content of 2 files | odogbolu98 | Shell Programming and Scripting | 3 | 09-10-2002 08:44 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Creating a tabulated file from content of 2 or more files
Hi all
I need specific fields from a file to be tabulated into a single file. I have a file with the following :- FIELD1 InfoA FIELD2 InfoB FILED3 InfoC FIELD1 InfoD FIELD2 InfoE FIELD3 InfoF The output I would like is as follows :- InfoA|InfoB|InfoC InfoD|InfoE|InfoF Any ideas. I have though of using grep and cut to create a file for each field and then use sed to read each line and echo it into a single line, however have not been able to. Thx J |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
file:
Code:
FIELD1 InfoA FIELD2 InfoB FILED3 InfoC FIELD1 InfoD FIELD2 InfoE FIELD3 InfoF Code:
InfoA InfoB InfoC InfoD InfoE InfoF Code:
awk ' {
if(NR % 3 == 0) {continue}
if(NF > 2)
{
printf("%s %s ", $2, $4)
continue
}
printf("%s\n", $2)
} ' filename
|
|
#3
|
|||
|
|||
|
Jim's code appeared to be correct, so I condensed it:
Code:
4==NF { printf "%s|%s|", $2, $4 }
2==NF { print $2 }
|
|||
| Google The UNIX and Linux Forums |