Sponsored Content
Top Forums Shell Programming and Scripting Need help in AWK;Search String and rearrange columns Post 302113332 by spring_buck on Thursday 5th of April 2007 07:34:20 AM
Old 04-05-2007
Need help in AWK;Search String and rearrange columns

Hi AWK Experts,

file1.txt contains:
29b11b820ddcc:-|OHad.perWrk|spn_id=AH111|spn_ordtyp=MY_REQ|msg_typ=ah.ntf.out|spn_ordid=928176|spn_nid=3|msg_strt=1 175615334703|msg_que=oput|diff=371|17:48:55,074|17:48:55,084|10

file2.txt contains:
29b11b820ddcc:-|spn_id=QA999|spn_ordid=98976098|spn_ordtyp=MY_RES|OHad.perWrk|msg_strt=11756153398760|diff=1571|msg _typ=ah.out.res|msg_que=res_oput|17:48:55,074|17:48:55,084|10


The columns in the input record that match below string must be selected and printed out in the same order as given below.
$1 -> OHad
$2 -> spn_id
$3 -> spn_ordid
$4 -> spn_ordtyp
$5 -> msg_typ
$6 -> spn_nid
$7 -> msg_que
$8 -> diff
$9 -> HH:MI:SS,sss
$10 -> 9999 (i.e., number of any length)

Hence the targetfile.txt must contain:
OHad.perWrk|spn_id=AH111|spn_ordid=928176|spn_ordtyp=MY_REQ|msg_typ=ah.ntf.out|spn_nid=3|msg_que=opu t|diff=371|17:48:55,074|17:48:55,084|1000
OHad.perWrk|spn_id=QA999|spn_ordid=98976098|spn_ordtyp=MY_RES|msg_typ=ah.out.res||msg_que=res_oput|d iff=1571|17:48:55,074|17:48:55,084|990810

Please note that [msg_strt] column is not required and [spn_nid] is required but is missing in file2.txt hence a blank is acceptable.

Could you please help me in getting the concept or a working prototype using AWK or any better tool that runs in shell script.

with best regrads,
Spring-Buck
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with a script to rearrange columns

I have a file that is semi-colon delimited and the column headers are always the same but the column number is totally random each time this file is generated. I don't have the skills to make a script for this so maybe someone can help. I would like to be able to take this file which has over... (11 Replies)
Discussion started by: n3al10
11 Replies

2. Shell Programming and Scripting

awk/sed search lines in file1 matching columns in file2

Hi All, as you can see I'm pretty new to this board. :D I'm struggling around with small script to search a few fields in another file. Basically I have file1 looking like this: 15:38:28 sz:10001 pr:14.16 15:38:28 sz:10002 pr:18.41 15:38:29 sz:10003 pr:19.28 15:38:30 sz:10004... (1 Reply)
Discussion started by: floripoint
1 Replies

3. UNIX for Dummies Questions & Answers

Rearrange columns and rows with awk

Hello, I have the following problem I have two columns with numbers arranged as follows: x1 y1 x2 y2 .... .... x250 y250 Now I need them arranged as follows: "string a" x1 y1 x1 y2 "string b" "string a" x1 y2 x2 y2 (3 Replies)
Discussion started by: Tom46
3 Replies

4. Shell Programming and Scripting

awk help to search columns in two files

Hello, I'm trying to compare multiple columns between two files. I would like to use columns 1,2 from file1 and search file2 in columns 2,3 for any matches. If they match, then print columns 2,3 from file2. file1 11:22:33:44:55:66|2010-07-25 12:30|xyz 22:22:22:22:22:22|2010-07-25... (5 Replies)
Discussion started by: pinseeker
5 Replies

5. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

6. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

7. Shell Programming and Scripting

Using awk to rearrange fields

Hi, I am required to arrange columns of a file i.e make the 15th column into the 1st column. I am doing awk 'begin {fs=ofs=","} {print $15,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14}' ad.data>ad.csv the problem is that column 15 gets to column 1 but it is not comma separated with the... (10 Replies)
Discussion started by: seddoubt
10 Replies

8. Shell Programming and Scripting

Rearrange Lines with awk

I need to rearrange the lines in the input file in the example below: Input: LG1 R500 A-170 F1:81 F1:22 F2:32 F1:71 LG1 R700 A-203 F2:17 E2:18 LG1 R700 B-224 E1:9 LG2 R500 C-235 E2:9 F2:17 Output: LG1 R500 A-170 F1:81 LG1 R500 A-170 F1:22 LG1 R500 A-170 F2:32 LG1 R500 A-170... (2 Replies)
Discussion started by: aydj
2 Replies

9. UNIX for Dummies Questions & Answers

Transpose matrix, and rearrange columns common with another file

This is my first post, I apologize if I have broken rules. Some assistance with the following will be very helpful. I have a couple of files, both should ultimately have common columns only, arranged in the same order. This file needs to be transposed, to bring the rows to columns ... (2 Replies)
Discussion started by: abh.kumar
2 Replies

10. Shell Programming and Scripting

Rearrange a file (2000 base64 strings in 1 row into 1 string by rows)

I have 1 row which contains abouts 20000 base64 string. e.g: /p4bdllBS8qcvW/69GUYej8nEv6gwt7UAYl0g==WZdjwTUQX9UEKsT/zWaZdQ==uI would like rearrange this file by base64 strings. So the output should be this ( 1 string in 1 row): 69GUYej8nEv6gwt7UAYl0g== WZdjwTUQX9UEKsT/zWaZdQ==How could I do... (4 Replies)
Discussion started by: freeroute
4 Replies
XZDIFF(1)							     XZ Utils								 XZDIFF(1)

NAME
xzcmp, xzdiff, lzcmp, lzdiff - compare compressed files SYNOPSIS
xzcmp [cmp_options] file1 [file2] xzdiff [diff_options] file1 [file2] lzcmp [cmp_options] file1 [file2] lzdiff [diff_options] file1 [file2] DESCRIPTION
xzcmp and xdiff invoke cmp(1) or diff(1) on files compressed with xz(1), lzma(1), gzip(1), or bzip2(1). All options specified are passed directly to cmp or diff. If only one file is specified, then the files compared are file1 (which must have a suffix of a supported com- pression format) and file1 from which the compression format suffix has been stripped. If two files are specified, then they are uncom- pressed if necessary and fed to cmp(1) or diff(1). The exit status from cmp or diff is preserved. The names lzcmp and lzdiff are provided for backward compatibility with LZMA Utils. SEE ALSO
cmp(1), diff(1), xz(1), gzip(1), bzip2(1), zdiff(1) BUGS
Messages from the cmp(1) or diff(1) programs refer to temporary filenames instead of those specified. Tukaani 2009-07-05 XZDIFF(1)
All times are GMT -4. The time now is 08:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy