awk - Extract 4 lines in Column to Rows Tab Delimited between tags


Trivia Category: Science: Computers
Difficulty: Medium
Early RAM was directly seated onto the motherboard and could not be easily removed.
True or False?

 
Thread Tools Search this Thread
# 1  
awk - Extract 4 lines in Column to Rows Tab Delimited between tags

I have tried the following to no avail.
Code:
xargs -n8 < test.txt
awk '{if(NR%6!=0){p=""}else{p="\n"};printf $0" "p}' Mod_Alm_log.txt > test.txt

I have tried different variations of the above, the problem is mixes lines together.
And it includes the tags "%a and %A" I need them to be all tab delimited on one line, like this:

-PerceivedSeverity=4
-EventTime=20130226022200
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16
-SPtext=RADIO X-CEIVER ADMINISTRATION REMOTE OMT OVER IP
-PCtext=SWITCHING DEVICES
Code:
%a
-PerceivedSeverity=4
-EventTime=20130226022200
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16
-SPtext=RADIO X-CEIVER ADMINISTRATION REMOTE OMT OVER IP ENABLED
-PCtext=SWITCHING DEVICES
%A

%a
-PerceivedSeverity=3
-EventTime=20130303160300
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16
-SPtext=APPLICATION DETECTED SOFTWARE ERROR
-PCtext=Software error
%A

%a
-PerceivedSeverity=4
-EventTime=20130409163500
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16,BssFunction=BSS_ManagedFunction,BtsSiteMgr=CT000
-SPtext=RADIO X-CEIVER ADMINISTRATION MANAGED OBJECTS IN TRANSCEIVER GROUP MANUALLY BLOCKED
-PCtext=Manually invoked fault or abnormal situation.
%A

%a
-PerceivedSeverity=3
-EventTime=20130417075700
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16,BssFunction=BSS_ManagedFunction,BtsSiteMgr=CT311
-SPtext=RADIO X-CEIVER ADMINISTRATION MANAGED OBJECT FAULT
-PCtext=Different causes possible for same message
%A

%a
-PerceivedSeverity=3
-EventTime=20130417075700
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16,BssFunction=BSS_ManagedFunction,BtsSiteMgr=CT311
-SPtext=RADIO X-CEIVER ADMINISTRATION MANAGED OBJECT FAULT
-PCtext=Different causes possible for same message
%A

%a
-PerceivedSeverity=3
-EventTime=20130417075700
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16,BssFunction=BSS_ManagedFunction,BtsSiteMgr=CT311
-SPtext=RADIO X-CEIVER ADMINISTRATION MANAGED OBJECT FAULT
-PCtext=Different causes possible for same message
%A

%a
-PerceivedSeverity=3
-EventTime=20130430033500
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16,BssFunction=BSS_ManagedFunction,BtsSiteMgr=CT733
-SPtext=RADIO X-CEIVER ADMINISTRATION MANAGED OBJECT FAULT
-PCtext=Different causes possible for same message
%A

%a
-PerceivedSeverity=2
-EventTime=20130501163000
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16
-SPtext=CELL RESTRICTION ACTIVATED
-PCtext=SWITCHING DEVICES
%A

%a
-PerceivedSeverity=3
-EventTime=20130501110100
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16,BssFunction=BSS_ManagedFunction,BtsSiteMgr=WS207
-SPtext=RADIO X-CEIVER ADMINISTRATION MANAGED OBJECT FAULT
-PCtext=Different causes possible for same message
%A

%a
-PerceivedSeverity=1
-EventTime=20130501221700
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16,BssFunction=BSS_ManagedFunction,BtsSiteMgr=CT103
-SPtext=RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT
-PCtext=Different causes possible for same message
%A

%a
-PerceivedSeverity=3
-EventTime=20130502003000
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16
-SPtext=DIGITAL PATH QUALITY SUPERVISION
-PCtext=Threshold crossed
%A

%a
-PerceivedSeverity=3
-EventTime=20130502010000
-ObjectOfReference=SubNetwork=ONRM_ROOT_MO,SubNetwork=AXE,ManagedElement=CRBSC16
-SPtext=DIGITAL PATH QUALITY SUPERVISION
-PCtext=Threshold crossed
%A


Last edited by vbe; 05-02-2013 at 10:38 AM.. Reason: code tags...
# 2  
Code:
awk '/^%a/||/^$/{next}!/^%/{ORS=OFS}/^%/{$0="";ORS=RS}1' OFS='\t' file.txt

# 3  
Yoda - Thanks for your reply, i first received the error:
Code:
/: Event not found.

tried again and got:
Code:
awk: syntax error near line 1
awk: bailing out near line 1

I tried to put in a file and execute against the file and same result:
Code:
awk: syntax error near line 1
awk: bailing out near line 1


Last edited by radoulov; 05-02-2013 at 11:42 AM..
# 4  
In Solaris / SunOS use /usr/xpg4/bin/awk or nawk instead of awk
# 5  
Ok, I'm sorry, still missing something. Does the format change from awk to nawk?
Code:
dreid12@atgapp01> nawk '/^>/{$0=(NR>1)?RS $0:$0;ORS=RS}!/>/{ORS=""}END{printf "\n"}1' Mod_Alm_log.txt
nawk '/^>/{$0=(NR>1)?RS $0:$0;ORS=RS}/usr/xpg4/bin/awk '/^%a/ || /^$/{next}^%/{ORS=OFS}/^%/{$0="" ; ORS=RS}1' OFS='\t' Mod_Alm_log.txt>/{ORS=""}END{printf "\n"}1' Mod_Alm_log.txt
nawk: syntax error at source line 1
 context is
        /^>/{$0=(NR>1)?RS $0:$0;ORS=RS}/usr/xpg4/bin/awk >>>  /^ <<< %a/
nawk: bailing out at source line 1
Variable name must contain alphanumeric characters.


Code:
dreid12@atgapp01> /usr/xpg4/bin/awk '/^%a/||/^$/{next}'/^%a/ || /^$/{next}^%/{ORS=OFS}/^%/{$0="" ; ORS=RS}1'%/{ORS=OFS}/^%/{$0="";ORS=RS}1' OFS='\t' Mod_Alm_log.txt
Illegal variable name.


Last edited by radoulov; 05-02-2013 at 05:31 PM..
# 6  
Please use code tags when posting any code fragments or data samples.

I see you made some modification in the code that I posted!

What do you get when you run below code?
Code:
/usr/xpg4/bin/awk '/^%a/||/^$/{next}!/^%/{ORS=OFS}/^%/{$0="";ORS=RS}1' OFS='\t' Mod_Alm_log.txt

# 7  
Code:
/usr/xpg4/bin/awk '/^%a/||/^$/{next}!/^%/{ORS=OFS}/^%/{$0="";ORS=RS}1' OFS='\t' Mod_Alm_log.txt

Code:
/usr/xpg4/bin/awk '/^%a/||/^$/{next}awk%/{ORS=OFS}/^%/{$0="";ORS=RS}1' OFS='\t' Mod_Alm_log.txt

/usr/xpg4/bin/awk: /{ORS=OFS}/: syntax error Context is:
>>> /^%a/||/^$/{next}awk%/{ORS=OFS}/ <<<

Last edited by mytouchsr; 05-02-2013 at 12:08 PM.. Reason: code tags error
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

2. UNIX for Dummies Questions & Answers

Sort tab delimited file according to which rows have missing values

Hello! I have a tab delimited file with values in three columns. Some values occur in all three columns, other values are present in only one or two columns. I would like to sort the file so that rows with no missing values come first, rows with one missing values come next, and rows with two... (9 Replies)
Discussion started by: MBarrett1213
9 Replies

3. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

4. Shell Programming and Scripting

Delete an entire column from a tab delimited file

Hi, Can anyone please tell me about how we can delete an entire column from a tab delimited file? Mu input_file.txt looks like this: And I want the output as: I used the below code nawk -v d="1" 'BEGIN{FS=OFS="\t"}{$d=""}{print}' input_file.txtBut in the output, the first column is... (5 Replies)
Discussion started by: sampoorna
5 Replies

5. UNIX for Advanced & Expert Users

merge two tab delimited file with exact same number of rows in unix/linux

Hi I have two tab delimited file with different number of columns but same number of rows. I need to combine these two files in such a way that row 1 in file 2 comes adjacent to row 1 in file 1. For example: The content of file1: field1 field2 field3 a1 a2 a3 b1 b2 b3... (2 Replies)
Discussion started by: mary271
2 Replies

6. Shell Programming and Scripting

Extract second column tab delimited file

I have a file which looks like this: 73450 articles and news developmental psychology 2006-03-30 16:22:40 1 http://www.usnews.com 73450 articles and news developmental psychology 2006-03-30 16:22:40 2 http://www.apa.org 73450 articles and news developmental psychology 2006-03-30... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

7. UNIX for Dummies Questions & Answers

Using awk to log transform a column in a tab-delimited text file?

How do I use awk to log transform the fifth column of a tab-delimited text file? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

8. UNIX for Dummies Questions & Answers

How to echo space or tab delimited values into rows?

Hi, I have the following code: LIST=`ls | grep '.sql$'` echo $LIST The above code will give me something like.. file1.sh file2.sh file3.sh file4.sh file5.sh I want to display the values into rows using echo like... file1.sh file2.sh (5 Replies)
Discussion started by: adshocker
5 Replies

9. Shell Programming and Scripting

So I converted columns to rows but I want it to be tab delimited and also I want.....

Hi, So my file looks like this: title number JR 2 JR 2 JR 4 JR 5 NM 5 NM 8 NM 2 NM 8 I used this line that I wrote to convert it to rows so it will look like this: awk -F"\t" '!/^$/{a=a" "$3} END {for ( i in a) {print i,a}}' occ_output.tab > test.txt JR 2 2 4 5 NM 5 8... (4 Replies)
Discussion started by: kylle345
4 Replies

10. UNIX for Dummies Questions & Answers

Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

Hey Everybody, I am having much trouble figuring this out, as I am not really a programmer..:mad: Datafile.txt Column0 Column1 Column2 ABC DEF xxxGHI I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies

Featured Tech Videos