parsing file

Hi
I need to parse a file in the following format

.PCI\Image test\Batch::I0Main

Status code = 1

.Test\Batch::Tgg0Main

Status code = 1

and need the output like

PCI\Image test
Test

I tried using simple awk command

awk -F"\\" '{print $1}'

but it just gives

PCI
Test

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

Thanks
Arif

I'm not sure if this helps. I did a little command line sample for you if I understood correctly.

Duplicates your data?

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.

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.

jnetnix@nix:~$ cat /tmp/test.txt | grep "^\." | sed -r 's/^\.//' | nawk -v OFS='\' -F '\' {'NF=NF-1; print;'}
PCI\Image test
Test

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

```text
 and 
```

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

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

Transaction\Operating Fund\Batch::OF0Main

Status code = 1

and the out put needs to be like

Transaction\Operating Fund

.Sorry for the confusion.

Thanks
Arif

sed -n 's#\(.*\)\\.*#\1#p' myFile
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

sed -n 's#.*\\\(.*\)#\1#p' myFile
awk -F'\\' '
 /[Tt]est/ {
    if (NF > 2) printf "%s\\%s\n", $1, $2
    else print $1
  }' "$file"