Print required values at end of the file by using AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print required values at end of the file by using AWK
# 1  
Old 04-20-2011
Print required values at end of the file by using AWK

I am looking help in awk, quick overview. we will get feed from external system . The input file looks like below.


Code:
Detail Id Info Id Order Id STATUS Status Date FileDetail 
99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM 60_R010|BDLPRICE|634691922|DATA|Y|Y|634691938|20110417|C|634691927-1|32011|G8618|H7174-1||||||||||||||||||||||||||||||



FileDetails column value is in pipe delimited.

My request is to create new file with all above column values and extra columns values at the end . Here my extra column names are (AID,SID, DATE) . The values of this new three columns should populate from FileDetail value. I am looking my output file like below
Code:
Detail Id Info Id Order Id STATUS Status Date FileDetail AID SID DATE 
99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM 60_R010|BDLPRICE|634691922|DATA|Y|Y|634691938|20110417|C|634691927-1|32011|G8618|H7174-1|||||||||||||||||||||||||||||| 634691922 634691938 20110417

Last three values(634691922 634691938 20110417) I have copied by FileDetail values that are pipe delimited which are in bold.

I tried with bleow command but did not get required output.

Code:
awk -F'[ |]+' '{ print ($1 "\t" $2 "\t" $3 "\t" $4 "\t" $5 "\t" $6 "\t" $9 "\t" $13 "\t" $14)} ' input.txt

any other solution is appreciate.

Thanks,
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-20-2011 at 06:24 PM.. Reason: code tags, please!
# 2  
Old 04-20-2011
Will this work for you:
Code:
sed 's/$/634691922 634691938 20110417/' Inp_File

# 3  
Old 04-20-2011
thanks for update. when i ran same command I am getting same values for other records like bleow.

Code:
sed 's/$/634691922 634691938 20110417/' input.txt

Code:
Detail Id    Info Id    Order Id         STATUS    Status Date               File Detail                                                                                                                          634691922 634691938 20110417
98850008     816148     CMOG221598756    PR        04-02-2011 06:00:24PM     60_R010|BDLPRICE|596695619|DATA|Y|N|596695629|20110402|C|846101152-1|26108|Y5893|H7239-1||||||||||||||||||||||||||||||               634691922 634691938 20110417
98850009     816148     CMOG221598771    PR        04-02-2011 06:00:26PM     60_R010|BDLPRICE|480566958|DATA|Y|Y|480566977|20110402|C|480566963-1|32010|G8607|H7187-1||||||||||||||||||||||||||||||               634691922 634691938 20110417 (these values should replace with above bold Green color values)
98850010     816148     CMOG221598780    PR        04-02-2011 06:00:28PM     60_R010|BDLPRICE|610843968|DATA|Y|N|610843981|20110402|C|610843972-1|25930|Y4820|H7438-1||||||||||||||||||||||||||||||               634691922 634691938 20110417 (these values should replace with above bold RED color values)



This will work same value for all records. but I want to check reach record in input file and print the values at end. above two records in green and red color are output examaples.

Thanks
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!


---------- Post updated at 05:15 PM ---------- Previous update was at 05:01 PM ----------

I am looking the output file as below.

Code:
Detail Id    Info Id    Order Id         STATUS    Status Date               File Detail                                                                                                                          
98850008     816148     CMOG221598756    PR        04-02-2011 06:00:24PM     60_R010|BDLPRICE|596695619|DATA|Y|N|596695629|20110402|C|846101152-1|26108|Y5893|H7239-1||||||||||||||||||||||||||||||               596695619 596695629 20110402
98850009     816148     CMOG221598771    PR        04-02-2011 06:00:26PM     60_R010|BDLPRICE|480566958|DATA|Y|Y|480566977|20110402|C|480566963-1|32010|G8607|H7187-1||||||||||||||||||||||||||||||               480566958 480566977 20110402
98850010     816148     CMOG221598780    PR        04-02-2011 06:00:28PM     60_R010|BDLPRICE|610843968|DATA|Y|N|610843981|20110402|C|610843972-1|25930|Y4820|H7438-1||||||||||||||||||||||||||||||               610843968 610843981|20110402


Last three values I have picked from filedetail values which is delmited by pipe.(Third,7th and 8th value)

thanks

Last edited by Franklin52; 04-21-2011 at 03:09 AM.. Reason: code tags, please!
# 4  
Old 04-21-2011
Out of curiosity, would this have worked as well?
Code:
awk -F'[ |]' '/^[0-9]/ {$49=$9; $50=$13; $51=$14} {print $0, $49, $50, $51}' input.txt

# 5  
Old 04-21-2011
with the above command i am getting blank values separeated by coma.

Code:
awk -F'[ |]' '/^[0-9]/ {$49=$9; $50=$13; $51=$14} {print $0, $49, $50, $51}' input.txt >> two.txt

obbhvpd1> vi two.txt
"two.txt" 196 lines, 42138 characters
Code:
Detail Id    Info Id    Order Id         STATUS    Status Date               File Detail                                                                                                                          ,,,,,
98850008     816148     CMOG221598756    PR        04-02-2011 06:00:24PM     60_R010|BDLPRICE|596695619|DATA|Y|N|596695629|20110402|C|846101152-1|26108|Y5893|H7239-1||||||||||||||||||||||||||||||               ,,,,,
98850009     816148     CMOG221598771    PR        04-02-2011 06:00:26PM     60_R010|BDLPRICE|480566958|DATA|Y|Y|480566977|20110402|C|480566963-1|32010|G8607|H7187-1||||||||||||||||||||||||||||||               ,,,,,
98850010     816148     CMOG221598780    PR        04-02-2011 06:00:28PM     60_R010|BDLPRICE|610843968|DATA|Y|N|610843981|20110402|C|610843972-1|25930|Y4820|H7438-1||||||||||||||||||||||||||||||               ,,,,,
98850011     816148     CMOG221598790    PR        04-02-2011 06:00:30PM     60_R010|BDLPRICE|615320070|DATA|Y|Y|615320086|20110402|C|615320074-1|25930|Y4820|H7262-1||||||||||||||||||||||||||||||               ,,,,,
98850012     816148     CMOG221598800    PR        04-02-2011 06:00:32PM     60_R010|BDLPRICE|616033096|DATA|Y|Y|616033107|20110402|C|616033098-1|32010|G8607|H7176-1||||||||||||||||||||||||||||||               ,,,,,

Thanks.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-21-2011 at 11:18 AM.. Reason: once AGAIN - please use code tags!
# 6  
Old 04-21-2011
See if this works for you:
Code:
sed 's/.*|\([0-9]\{9\}\)|.*|\([0-9]\{9\}\)|\([0-9]\{8\}\)|.*/& \1 \2 \3/' Inp_File

# 7  
Old 04-21-2011
This command works perfect for me. thank you very much. But I am looking all column values to create with tab delimited or comma(m)delimited in new file. When I try with below command its the values are not creating with tab delimited.

Code:
sed 's/.*|\([0-9]\{9\}\)|.*|\([0-9]\{9\}\)|\([0-9]\{8\}\)|.*/& \1 \2 \3/' '\t' input.fil > one.txt

Also I have two other input files that need to create with same . As I am new to SED I can't able to create sed by refering your command. Can you please check and provide sed command for below files too with tab delimited out put file.
Code:
Detail Id    Info Id    Order Id         STATUS    Status Date               File Detail
99191222     820308     CMOG224013751    PR        04-20-2011 07:00:27PM     20_R28|BQTBIZ_PRICEUP|776598279|776598280|20110420|C|Y7371-1|26342|Y7364|H7018-1|Y|N| 776598279 776598280 20110420
99191223     820308     CMOG224013767    PR        04-20-2011 07:00:31PM     20_R28|BQTBIZ_PRICEUP|772963162|772963163|20110420|C|Y7291-1|25525|Y2548|H7082-1|Y|N| 772963162 772963163 20110420

Code:
Detail Id    Info Id    Status    Status Date               File Detail            Error Code Error Desc
99191240     820308     ER        04-20-2011 07:01:25PM     20_R28|BQTBIZ_PRICEUP|16716056|16716059|20110420|C|G5935-1|6500|G6725|H7027-1|Y|N|           226113     Action is not allowed on a service with pending orders 16716056 16716059 20110420
99191489     820308     ER        04-20-2011 07:02:23PM     20_R28|BQTBIZ_PRICEUP|780442679|780442680|20110420|C|Y2516-1|25790|Y4490|H7094-1|Y|N|  780442679 780442680 20110420  

your help is greatly thank full.

---------- Post updated at 03:40 PM ---------- Previous update was at 11:58 AM ----------

any help for my request..

Last edited by Franklin52; 04-21-2011 at 03:47 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to extract values and print at end of each line

In the below perl I am trying to extract and print the values AF1=, the GT value, and F or QUAL diveded by 33 (rounded to the nearest whole #). The GT value is at the end after the GT:PL so all the possibilities are read into a hash h, then depending on the value that is in the line the... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

awk one liner to print to end of line

Given: 1,2,whatever,a,940,sot how can i print from one particular field to the end of line? awk -F"," '{print $2 - endofline}' the delimiter just happens to be a comma "," in this case. in other cases, it could be hypens: 1---2---whatever---a---940---sot (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

Required help to print diff columns for 2 patterns using awk

Hi All, I need help for below scenario : I have a principals.xml_24092012backup file : cat principals.xml_24092012backup </user> <user username="eramire" password="2D393C01720749256303D204826A374D9AE9ABABBF8A"> <roleMapping rolename="VIEW_EVERYTHING"/> </user> ... (2 Replies)
Discussion started by: kiran_j
2 Replies

5. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

6. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

7. UNIX for Advanced & Expert Users

Awk to print values of second file

Hello, I have a data file with 300,000 records in it, and another file which contains only the line numbers of roughly 13,000 records in the data file which have data integrity issues. I'm trying to find a way to print the original data by line number identified in the second file. How can I do... (2 Replies)
Discussion started by: peteroc
2 Replies

8. Shell Programming and Scripting

How to Print from matching word to end using awk

Team, Could some one help me in Printing from matching word to end using awk For ex: Input: I am tester for now I am tester yesterday I am tester tomorrow O/p tester for now tester yesterday tester tomorrow i.e Starting from tester till end of sentence (5 Replies)
Discussion started by: mallak
5 Replies

9. UNIX and Linux Applications

Print date at END clause of AWK

Hi to all! I 'm new in unix programing so... may be I decided a wrong tool to solve the problem but anyway... all road goes to rome jajaja. My question is: There is any way to print date at the END clause of an AWK script. I mean, I'm writing a tool with AWK and the results are redirected to a... (4 Replies)
Discussion started by: fmeriles
4 Replies

10. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies
Login or Register to Ask a Question