- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Korn shell script problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 01:39 AM
тАО11-24-2004 01:39 AM
y=1
x=1
while [ y -ne 0 ]
do
awk "NR==$x" $TAR > $BUF
let "x=x+1"
y=`wc -c $BUF`
done
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 01:43 AM
тАО11-24-2004 01:43 AM
Re: Korn shell script problem
while [ $y -ne 0 ]
instead of
while [ y -ne 0 ]
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 01:48 AM
тАО11-24-2004 01:48 AM
Re: Korn shell script problem
But is the awk command I issued correct?
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 01:49 AM
тАО11-24-2004 01:49 AM
SolutionI don't know what you are trying to do. Why do you want to use a script to read it line by line? Can you do something like
while read line
do
echo $line
done < $TAR
to read line by line?.
If you insist on using the script, then there are couple of issues.
1. while [ y -ne 0 ] should be while [ $y -ne 0 ]. Use [[ and ]] instead.
2. awk "NR==$x" won't work. You can't assing a shell variable inside awk. Do
awk -v x=$x 'NR==x' $TAR > $BUF
No $ for variables inside awk.
3. Try (( x = $x + 1 )) instead of let.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 01:59 AM
тАО11-24-2004 01:59 AM
Re: Korn shell script problem
as advised I used
"awk -v x=$x 'NR==x' $TAR > $BUF"
and it produces
awk: syntax error near line 1
awk: bailing out near line 1
what could be wrong?
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 02:16 AM
тАО11-24-2004 02:16 AM
Re: Korn shell script problem
$TAR=testfile
$x=2
$awk -v x=$x 'NR==x' $TAR
testline 2
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 02:18 AM
тАО11-24-2004 02:18 AM
Re: Korn shell script problem
When I first started working with unix, one of my colleagues said "A shell script doesn't deserve the name shell script unless it contains at least one awk".
I don't agree with him! Sri's "while read line" suggestion is just as effective as awk and easier to script.
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 07:53 AM
тАО11-24-2004 07:53 AM
Re: Korn shell script problem
an awk program, but only because the shell
substitutes inside of double quotes:
x=2
awk "NR == $x" some_file
If you use single quotes the shell won't
substitute for $x.
However, I don't understand why you are
doing this in such a roundabout manner.
Replacing your entire program with
"cat $TAR" will also read from TAR until
EOF. What are you trying to accomplish?
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 10:37 AM
тАО11-24-2004 10:37 AM
Re: Korn shell script problem
DOes that mean I can read line 1 of the file this way:
"
TAR = filename
x=1
while read x
do
echo $x
done < $TAR
"
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2004 11:51 AM
тАО11-24-2004 11:51 AM