Solved

Shell script awk command

Posted on 2015-01-16
2
106 Views
Last Modified: 2015-09-07
Hi,
I am tryin to transfer the data from list20.prn file to output.txt but somehow its returnin 0 bytes..null file...

please advise.

echo "Filter out non dialer processed A/R - Start"
     awk 'BEGIN{FS="\",\"";OFS="|"} {$1=$1; print $0}' list20.prn > output.txt
     rm -f out.txt
     cat output.txt | while read LINE
     do
     record=`echo $LINE`
        tenth=`echo $record | cut -f10 -d"|"`
        if [ "$tenth" != "" ]
        then
           echo $LINE >> out.txt
        fi
     done
     awk 'BEGIN{FS="|";OFS="\",\""} {$1=$1; print $0}' out.txt > output.txt
     mv output.txt list20.prn
     echo "Filter out - End"

Thanks
Aman
list20.prn
0
Comment
Question by:amankhan2005
  • 2
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40554201
Instead of the first "awk" use

sed 's/\",\"/|/g' list20.prn > output.txt

and instead of the second "awk" use

sed 's/|/\",\"/g' out.txt > output.txt

The output file will remain empty nevertheless - the tenth field is always empty, at least in the sample file you posted.
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 40554214
Or do everything in a single awk:

awk 'BEGIN {FS="\",\""} {if($10!="") print}' list20.prn > output.txt
mv output.txt list20.prn
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EXCHANGE, ACTIVE DIRECTORY 4 65
Launch Process with NOT as Administrator 15 91
How to check the PVU´s on AIX TSM servers? 3 95
awk file 6 55
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question