Solved

Shell script awk command

Posted on 2015-01-16
2
110 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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