Solved

Shell script awk command

Posted on 2015-01-16
2
90 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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now