![]() |
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 |
| 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 |
| reading text file line by line | MizzGail | Shell Programming and Scripting | 6 | 04-14-2008 07:58 AM |
| Line by line file reading... and more! | ProFiction | Shell Programming and Scripting | 6 | 07-26-2007 12:32 PM |
| Reading line by line from a file | tej.buch | Shell Programming and Scripting | 2 | 01-23-2006 02:50 AM |
| sed not outputting last line of input file | 2reperry | Shell Programming and Scripting | 3 | 12-16-2005 12:51 PM |
| Reading line by line from file. | akpopa | UNIX for Dummies Questions & Answers | 4 | 08-30-2001 11:20 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi everyone. I realise this is probably a bit of a noob question, but I'm actually a C# developer working on a legacy system, and can't remember much unix.
I want to read from a pipe-delimeted file like formatted thusly: idno|PRODUCT|Name|street town postcode|etc|etc|etc|etc idno|PRODUCT|Name|street town postcode|etc|etc|etc|etc idno|PRODUCT|Name|street town postcode|etc|etc|etc|etc I want to copy each line to another file, dependant upon the PRODUCT existing in a string variable I'm holding in memory: "prod1|prod2|prod3" ($products in example below) Therefore I was trying: for line in `cat $temp_dir/$Filename | awk '{ print $0 } '` do prod=`echo "$line" | awk ' BEGIN {FS="|"} {print $2} '` valid_prod=`echo $products | grep "$prod"` if [ -n "$valid_prod" ] ; then echo "$line" >> $new_file.txt fi done however this line variable seems to separate based on spaces, creating the new file as: idno|PRODUCT|Name|street town postcode|etc|etc|etc|etc Is there anyway I can pass each line through as a single parameter, regardless of spaces? Any help is greatfully appreciated, Dave |
| Bookmarks |
| Tags |
| awk, file, grep or, read, spaces, write |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|