parsing file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing file
# 1  
Old 08-17-2009
parsing file

Hi
I need to parse a file in the following format

Code:
.PCI\Image test\Batch::I0Main

Status code = 1

.Test\Batch::Tgg0Main

Status code = 1

and need the output like

Code:
PCI\Image test
Test

I tried using simple awk command
Code:
awk -F"\\" '{print $1}'

but it just gives
Code:
PCI
Test

and doesnt get rid of the empty lines and lines with status code .
Any help appriciated

Thanks
Arif

Last edited by vgersh99; 08-17-2009 at 04:54 PM.. Reason: code tags, PLEASE!
# 2  
Old 08-17-2009
I'm not sure if this helps. I did a little command line sample for you if I understood correctly.

Duplicates your data?
Code:
jnetnix@nix:~$ cat /tmp/test.txt 
.PCI\Image test\Batch::I0Main

Status code = 1

.Test\Batch::Tgg0Main

Status code = 1
jnetnix@nix:~$

Modified correctly? Of course this would may work depending on your full data file...if Batch is not there.
Code:
jnetnix@nix:~$ cat /tmp/test.txt | grep "^\." | sed -r 's/(^\.|\\Batch:.*)//g'
PCI\Image test
Test
jnetnix@nix:~$

Or...maybe better I snagged some nice nawk code from another post. This will split on the \ and remove the last field.
Code:
jnetnix@nix:~$ cat /tmp/test.txt | grep "^\." | sed -r 's/^\.//' | nawk -v OFS='\' -F '\' {'NF=NF-1; print;'}
PCI\Image test
Test

# 3  
Old 08-17-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 4  
Old 08-17-2009
Quote:
Originally Posted by jnetnix
I'm not sure if this helps. I did a little command line sample for you if I understood correctly.

Duplicates your data?
Code:
jnetnix@nix:~$ cat /tmp/test.txt 
.PCI\Image test\Batch::I0Main

Status code = 1

.Test\Batch::Tgg0Main

Status code = 1
jnetnix@nix:~$

Modified correctly? Of course this would may work depending on your full data file...if Batch is not there.
Code:
jnetnix@nix:~$ cat /tmp/test.txt | grep "^\." | sed -r 's/(^\.|\\Batch:.*)//g'
PCI\Image test
Test
jnetnix@nix:~$

Or...maybe better I snagged some nice nawk code from another post. This will split on the \ and remove the last field.
Code:
jnetnix@nix:~$ cat /tmp/test.txt | grep "^\." | sed -r 's/^\.//' | nawk -v OFS='\' -F '\' {'NF=NF-1; print;'}
PCI\Image test
Test

Thanks for the reply , the sed -r options doesnt works on my machine (soalris) . ALso there is no . in teh begining of teh text , the file is actually like below
Code:
Transaction\Operating Fund\Batch::OF0Main

Status code = 1

and the out put needs to be like
Code:
Transaction\Operating Fund

.Sorry for the confusion.

Thanks
Arif
# 5  
Old 08-17-2009
Code:
sed -n 's#\(.*\)\\.*#\1#p' myFile

# 6  
Old 08-27-2009
Code:
sed -n 's#\(.*\)\\.*#\1#p' myFile

The above code gives me PCI\Image test\ out of the string PCI\Image test\Batch::I0Main ,
How can I ge the last part in Batch::I0Main.

Sorry not pretty good at regular expression.

Thanks
Arif
# 7  
Old 08-27-2009
Quote:
Originally Posted by mabarif16
Code:
sed -n 's#\(.*\)\\.*#\1#p' myFile

The above code gives me PCI\Image test\ out of the string PCI\Image test\Batch::I0Main ,
How can I ge the last part in Batch::I0Main.

Sorry not pretty good at regular expression.

Thanks
Arif
Code:
sed -n 's#.*\\\(.*\)#\1#p' myFile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Parsing

Hi Gurus, i have files like this and i want to rename it. server1_0_Log0000597500 server1_0_Log0000597501 server1_0_Log0000597502 server1_0_Log0000597503 server1_0_Log0000597504 server1_0_Log0000597505 server1_0_Log0000597506 server1_0_Log0000597507 server1_0_Log0000597508... (7 Replies)
Discussion started by: fedora132010
7 Replies

2. Shell Programming and Scripting

parsing data from a big file using keys from another smaller file

Hi, I have 2 files format of file 1 is: a1 b2 a2 c2 d1 f3 format of file 2 is (tab delimited): a1 1.2 0.5 0.06 0.7 0.9 1 0.023 a3 0.91 0.007 0.12 0.34 0.45 1 0.7 a2 1.05 2.3 0.25 1 0.9 0.3 0.091 b1 1 5.4 0.3 9.2 0.3 0.2 0.1 b2 3 5 7 0.9 1 9 0 1 b3 0.001 1 2.3 4.6 8.9 10 0 1 0... (10 Replies)
Discussion started by: Lucky Ali
10 Replies

3. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

4. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Discussion started by: Rhije
3 Replies

5. UNIX for Dummies Questions & Answers

Script for parsing details in a log file to a seperate file

Hi Experts, Im a new bee for scripting, I would ned to do the following via linux shell scripting, I have an application which throws a log file, on each action of a particular work with the application, as sson as the action is done, the log file would vanish or stops updating there, the... (2 Replies)
Discussion started by: pingnagan
2 Replies

6. Shell Programming and Scripting

File Parsing Help

Hello, I have a file which contains groups of fields. These groups are separated by a blank line, to form a logical record. Each line consists of a field-value pair. If want to find all records where field 'd' has a value of '4' and if it does, I want the value of field 'a' (from the... (4 Replies)
Discussion started by: brawnr
4 Replies

7. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

8. Shell Programming and Scripting

need help in Parsing a CSV file and generate a new output file

Hi Scripting Gurus, I am trying to parse a csv file and generate a new output file. The input file will be a variable length in turns of rows and columns. output file will have 8 columns. we have three columns from the header for each set. just to give little bit more clarification each row... (15 Replies)
Discussion started by: vkr
15 Replies

9. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

10. Shell Programming and Scripting

Help me with parsing this file

Hi, I need a shell script that would parse this file /usr/share/i18n/locales/aa_DJ:title "Afar language locale for Djibouti (Cadu/Laaqo Dialects)." /usr/share/i18n/locales/aa_ER:title "Afar language locale for Eritrea (Cadu/Laaqo Dialects)." /usr/share/i18n/locales/aa_ER@saaho:title... (2 Replies)
Discussion started by: eamani_sun
2 Replies
Login or Register to Ask a Question