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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parsing a line in Shell Script unishiva Shell Programming and Scripting 3 11-01-2007 04:30 PM
Parsing line out of a file, please help !! xeniya Shell Programming and Scripting 5 05-31-2007 12:52 PM
problem parsing output file ragha81 Shell Programming and Scripting 13 03-21-2007 02:06 PM
Problem with parsing a large file gauravgoel Shell Programming and Scripting 6 10-18-2006 06:48 PM
parsing a delimited line monkeys Shell Programming and Scripting 11 07-12-2006 07:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-02-2006
rlwilli rlwilli is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 2
Problem parsing line in file

I am VERY new to unix scripting. I am having trouble parsing a line into fields for further processing.

I have this script:

#bin/sh

cat ztest2.txt | while read line
do
zvar1=`echo $line | cut -f6`
echo "zvar1 is " $zvar1
done

********************
ztest2.txt looks like:

1 2 3 4 5 6 7 8
2 3 4 5 6 7 8 9
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10 11

where the spaces in between the numbers are tabs.

the output of this script is:

zvar1 is 1 2 3 4 5 6 7 8
zvar1 is 2 3 4 5 6 7 8 9
zvar1 is 3 4 5 6 7 8 9 10
zvar1 is 4 5 6 7 8 9 10 11


if i just run from the command line:
cut -f6 ztest2.txt

i get
6
7
8
9

Can anyone help.
  #2 (permalink)  
Old 09-02-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 579

Code:
#bin/sh

cat ztest2.txt | while read line
do
zvar1=`echo $line | awk '{print $6}'`
echo "zvar1 is " $zvar1
done

  #3 (permalink)  
Old 09-02-2006
rlwilli rlwilli is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 2
Thank you. That works. Of course that's the simple part. My actual data is far more complicated than my example but at least I can move forward now.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0