![]() |
|
|
|
|
|||||||
| 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 |
| Formatting Output | dhanamurthy | Shell Programming and Scripting | 6 | 05-02-2008 08:43 AM |
| Formatting bdf output | Cameron | Shell Programming and Scripting | 5 | 04-09-2008 06:05 AM |
| formatting output | balaji_prk | Shell Programming and Scripting | 4 | 09-15-2007 06:23 AM |
| Formatting Script Output | liketheshell | Shell Programming and Scripting | 3 | 08-06-2007 07:38 AM |
| Formatting the output | Cameron | Shell Programming and Scripting | 7 | 02-15-2002 07:30 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Formatting output
Hi,
I am new to shell scripting, I ahve written a shell script which would extract me data, but my problem is I want to add a column name to my output. Using grep and sed I am getting my data from the input file. Sample data name : eric name : tom name : sean My output using grep and sed is : eric tom sean But I want my output as name eric tom sean I tried searching as much as possible in google and in the forum, but no luck. If it is a repeated question, I am extremely sorry. If someone can help me out in this regard, that would be great. I tried using awk '/name/ {print $2}' test.tmp , but this gives me only eric, tom,etcc..but name is not getting displayed. Your valuable help is really appreciated. Thanks in Advance Sandeep |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Try this code :
i=1 cat $my_input_file | while read line do if [ $i -eq 1 ] then echo $line | cut -d':' -f1 > $my_output_file fi echo $line | cut -d':' -f2 >> $my_output_file i=$(($i+1)) done cat $my_output_file Rgds. |
|
#3
|
||||
|
||||
|
Quote:
while read line; do ... done < $my_input_file Cheers ZB |
|
#4
|
|||
|
|||
|
Thanks
Hi,
Thanks very much for your replies, but I ahve come out with another work around. I am using a function like this ********************************* function extract { echo $1 grep "$1" /home/sjagadee/$2 | sed "s/$1//g"| sed "s/**//g" } ********************************* where in $1 would be my search criteria, $2 my filename. Thanks a ton Sandy |
|||
| Google The UNIX and Linux Forums |