The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-10-2005
Registered User
 

Join Date: Oct 2005
Posts: 2
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
Reply With Quote
Forum Sponsor
  #2  
Old 10-12-2005
Registered User
 

Join Date: Aug 2005
Location: Paris
Posts: 75
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.
Reply With Quote
  #3  
Old 10-13-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Quote:
Originally Posted by madmat
cat $my_input_file | while read line
UUoC

while read line; do
...
done < $my_input_file

Cheers
ZB
Reply With Quote
  #4  
Old 10-13-2005
Registered User
 

Join Date: Oct 2005
Posts: 2
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0