The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
print all even lines of a txt file ajp7701 Shell Programming and Scripting 1 04-17-2008 11:17 PM
print selected rows with awk tonet Shell Programming and Scripting 6 09-27-2007 06:23 AM
How to print specific lines with awk Bugenhagen Shell Programming and Scripting 10 08-16-2007 06:41 AM
How to print number of lines with awk ? maheshsri Shell Programming and Scripting 1 11-18-2005 02:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2007
tonet
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Question print selected lines

Hi everybody:
I try to print in new file selected lines from another file wich depends on the first column.

I have done a script like this:

Code:
	lines=( "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "21" "31" "41" "51" "55" "57" "58" )
	${lines[@]}
	for lines in ${lines[@]}
	do
	awk -v  target=$lines  ' $1 == target print $0 ' file1 >> file2
	done
But I have the next error:

Code:
./T-eff.sh: 42: Syntax error: "(" unexpected ------ where the line 42 correspond when I declare the array "lines"
Any suggestion?. Thanks in advance
  #2 (permalink)  
Old 10-08-2007
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
What shell are you using? In KSH the following works:

set -A lines = 1 2 3 4 5 6 7 8 9 10 11 21 31 41 51 55 57 58
print ${lines[12]}

will print '21'
  #3 (permalink)  
Old 10-08-2007
tonet
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Hi:
Thanks for your reply. I usually use the sh shell.
  #4 (permalink)  
Old 10-08-2007
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
I don't think the bourne shell supports arrays.
  #5 (permalink)  
Old 10-08-2007
tonet
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Hi again:
I have seen at "Advanced Bash-Scripting Guide" by Mendel Cooper that it is possible to use arrays on bourne shell scripts.
  #6 (permalink)  
Old 10-08-2007
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
Bash is the bourne again shell, the newer version of the bourne shell, or sh.

If you want bash, start your script with #!/bin/bash otherwise if no shell is selected sh will be used, and that doesn't support arrays as far as I know.
  #7 (permalink)  
Old 10-08-2007
tonet
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
I have done, I have changed:

Code:
#!/bin/sh
for

Code:
#!/bin/bash
and now it works correctly. Thnaks a lot.
Sponsored Links
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 06:59 AM.


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