how to cut off last column from the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to cut off last column from the output
# 1  
Old 11-04-2008
how to cut off last column from the output

I have a problem with my script. I am using following code
awk -F"," '{print $0,",",substr($2,3,3)}' $REG_InputFileName > $TargetSeqPath/Master.tmp

while read i
do
echo $i > $TargetSeqPath/Ref.tmp
OutFileName=`awk -F"," '{print $3}' $TargetSeqPath/Ref.tmp`
rm -f $TargetSeqPath/$OutFileName.dat
touch $TargetSeqPath/$OutFileName.dat
awk -F"," 'NR==FNR {col1[$1]=$3} NR!=FNR { if (col1[substr($2,3,3)]=="") {next} print $0}' $TargetSeqPath/Ref.tmp $TargetSeqPath/Master.tmp >> $TargetSeqPa
th/$OutFileName.dat
done < $RefInputFileName


In this script i am having output as following :

"UPDATE", "3000020113", "1-01-01", "THB" , 300
"UPDATE", "3000020307", "1-01-01", "THB" , 300
"UPDATE", "3000020409", "1-01-01", "USD" , 300
"UPDATE", "3000021126", "1-01-01", "USD" , 300

but i want to get rid of last column . Can anybody help me with this?

Thanks
# 2  
Old 11-04-2008
Post your input file and the desired output.

Regards
# 3  
Old 11-04-2008
REG_InputFileName :
"INSERT", "1000011206", "1-01-01", "THB"
"INSERT", "1000020307", "1-01-01", "USD"
"INSERT", "2000020113", "1-01-01", "USD"
"INSERT", "2000020411", "1-01-01", "THB"
"INSERT", "2000041125", "1-01-01", "USD"
"UPDATE", "1000020113", "1-01-01", "THB"
"UPDATE", "1000020307", "1-01-01", "THB"
"UPDATE", "1000020411", "1-01-01", "THB"
"UPDATE", "2000020411", "1-01-01", "USD"
"UPDATE", "2000020722", "1-01-01", "USD"
"UPDATE", "2000031221", "1-01-01", "THB"
"UPDATE", "3000020113", "1-01-01", "THB"
"UPDATE", "3000020307", "1-01-01", "THB"
"UPDATE", "3000020409", "1-01-01", "USD"
"UPDATE", "3000021126", "1-01-01", "USD"

RefInputFileName
100,OHC,MYH
200,OHC,SGH
300,OHC,INM


There will be three output files namely INM.dat, MYH.dat and SGH.dat
output for INM.dat is :

"UPDATE", "3000020113", "1-01-01", "THB"
"UPDATE", "3000020307", "1-01-01", "THB"
"UPDATE", "3000020409", "1-01-01", "USD"
"UPDATE", "3000021126", "1-01-01", "USD"
# 4  
Old 11-04-2008
Use nawk, gawk or /usr/xpg4/bin/awk on Solaris.

Code:
awk -F, 'NR==FNR{a[$1]=$3;next}
substr($2,3,3) in a{print > a[substr($2,3,3)]".dat"}
' RefInputFileName REG_InputFileName

Regards
# 5  
Old 11-04-2008
Hi Franklin,
I didn't understand where i need to use that code??
# 6  
Old 11-04-2008
It should be something like:

Code:
#!/bin/sh
  
RefInputFileName=".."  # set your variable here
REG_InputFileName=".."  # set your variable here

awk -F, 'NR==FNR{a[$1]=$3;next}
substr($2,3,3) in a{print > a[substr($2,3,3)]".dat"}
' "$RefInputFileName" "$REG_InputFileName"

Regards
# 7  
Old 11-04-2008
Hi franklin,

i am new to awk . Can you please exactly tell me where should i put this statement in my code. My code is exactly as above.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pick the column value based on another column using awk or CUT

My scenario is that I need to pick value from third column based on fourth column value, if fourth column value is 1 then first value of third column.Third column (2|3|4|6|1) values are cancatenated. Please someone help me to resolve this issue. Source column1 column2 column3 column4... (2 Replies)
Discussion started by: Ganesh L
2 Replies

2. Shell Programming and Scripting

cut the last column from the link

Hi, I need to cut the last of below link lrwxrwxrwx 1 e027025 denccefs 36 Oct 21 02:30 prodcode1 -> /efare1/LINUXMTP-4/HOTFIX111019A_5U4/ after cut I need this value HOTFIX111019A_5U4 Please help me. Thanks (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

3. Shell Programming and Scripting

Cut column and edit data

Mar 26 12:32:53 name sshd: 192.168.1.14 Mar 27 12:42:53 name sshd: 192.168.1.14 how to make this data in output as: "Mar 26 12:32:53","name","sshd","192.168.1.14" "Mar 27 12:42:53","name","sshd","192.168.1.14" anyone plzz help me out!!!!!!!!!!!!!! (4 Replies)
Discussion started by: jacky29
4 Replies

4. Shell Programming and Scripting

cut the first row first column value

Hi All, file create2.txt contains . /test.txt ./create.txt ./test2.txt test.txt contains inb-1|kuuhsdkjfhsd|djshfjksd|ndsbs896 inb-2|kuuhsdkjfhsd|djshfjksd|ndsbs896 inb-3|kuuhsdkjfhsd|djshfjksd|ndsbs896create.txt contains abv-1|kjsdgfjksd|sdkjbfhokjsd|skjdbfhjkosd... (8 Replies)
Discussion started by: adaleru
8 Replies

5. Shell Programming and Scripting

top output for six processes with the same name, output changed from column to row

Hi, I have a system under test, and I use a script that does a ps. The output, is in the following format, it's basically the timestamp, followed by the rss and vsize. 09:03:57 68404 183656 68312 181944 69860 217360 67536 182564 69072 183172 69032 199276 09:04:27 68752 183292 70000 189020... (5 Replies)
Discussion started by: Bloke
5 Replies

6. Shell Programming and Scripting

4 column tsv file, output 1 specific column

Hello all siteexplorer.search.yahoo.com can output results in tsv format, when opened in excel I get 4 columns. I would like to wget that file, which I can do. I would then like to pull the 2nd column and output it only. I've searched around and found a few bits and pieces but nothing I've... (6 Replies)
Discussion started by: casphar
6 Replies

7. UNIX for Advanced & Expert Users

cut a specific value from a column

Dear Friends, I have an output like this: 7072;0;7072901 7072;1001;7072902 7072;101;7072903 7072;102;7072904 7072;1101;7072905 7072;1301;7072906 7072;1401;7072907 7072;162;7072908 7072;1;7072909 and I need to print the value in the column 3 , row number 1. which is 7072901 only.... (2 Replies)
Discussion started by: sfaqih
2 Replies

8. Shell Programming and Scripting

To cut entire column from a file and apend it to another file as another column

file1.txt : india pakistan bangladesh japan canada africa USA srilanka Nepal file2.txt Delhi Tokyo washington I have to cut the first column of file1.txt and apend it with file2.txt as another column like this Delhi india Tokyo japan washington USA ... (4 Replies)
Discussion started by: sakthifire
4 Replies

9. Shell Programming and Scripting

cut column

I have a file as below, $vi myfile aaa;20071217 bbb;20070404 ccc;20070254 " if I want to cut the column 9-12 of the first line , the output should be 1217 , can advise how to write a script to get the result ? thx p.s. can a script that have only ONE line could do that ? (5 Replies)
Discussion started by: ust
5 Replies

10. Shell Programming and Scripting

cut the third column from a file

I have a text file which has the following data. There can be more lines in the file. But, I am only interested in these two lines which has ~ZZ~VISTN and ~ZZ~F159B segments. ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183 7~U~00200~000011258~0~P~< ... (8 Replies)
Discussion started by: isingh786
8 Replies
Login or Register to Ask a Question