?
Solved

Shell script awk command

Posted on 2015-01-16
2
Medium Priority
?
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1500 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 1500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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