![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to convert Fixed length file to delimited file. | satyam_sat | Shell Programming and Scripting | 7 | 04-03-2008 02:41 AM |
| Converting a Delimited File to Fixed width file | raghavan.aero | Shell Programming and Scripting | 2 | 06-06-2007 02:44 PM |
| Converting Tab delimited file to Comma delimited file in Unix | charan81 | Shell Programming and Scripting | 22 | 01-20-2006 09:24 AM |
| tab delimited file to commas | hcclnoodles | Shell Programming and Scripting | 6 | 08-16-2004 01:23 PM |
| Comma Delimited file | dbrundrett | Shell Programming and Scripting | 2 | 04-05-2004 10:50 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Delimited File Help
Hey guys I am new to unix programming and need some help with a task.
I have a file that is comma delimited with values like this 1,NEW.txt 1,OLD.txt 2,MONKEY.txt 3,FUN.txt 100,MONEY.txt I have a user enter a value for the type they want (1,2,3,100). I then want to compare the first column in the file to that entered value and return the second column in that file if it matches. If 1 is entered I want returned: NEW.txt OLD.txt I cannot figure out how to use awk, cut or sed to do this. Any help would be greatly appreciated. Thanks in advance folks! |
|
||||
|
Works here. Do you have a really old version of awk? The script itself is so trivial as to hardly contain any syntax at all -- does your awk understand -F and -v? If not, do you have access to nawk, or mawk, or gawk, ... or (gasp) Perl? (Hint: a2p)
|
|
||||
|
Thats a very good question, I have no idea what version of awk I have...
I have access to nawk but not the other two. And I do have access to Perl but know nothing about it. This ended up working for me... Can you see any issues with this? Code:
$VAR_NAM=$1
$FILE_LIST=$2
$TEMP_FILE=$3
awk -F, '$1=='"$VAR_NAM"' {print $2}' $FILE_LIST > $TEMP_FILE
Update... Using nawk the previous code worked fine with the IF statements thanks for the help folks! |
|
||||
|
Strictly speaking, you should put double quotes around the file names too. And obviously, when assigning to a variable, you don't put a dollar sign in front of the variable name. Other than that, schoolbook example -- good work.
Would still be interesting to learn if switching from awk to nawk would solve the problem you were having with the syntax error. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|