File handling

Hi All,

I need to extract the data from the text file. The data of the text file is shown below

#L 0.000017 4.329939 0.000017 4.716267 r7.9 P 1 1;Net=IN32

The extracted data should be IN32 . Could anyone help to script in c shell.?

YMMV:

sed 's/.*=\(.*\)$/\1/' myFile
awk -F= '{print $NF}' myFile
2 Likes

Hi.

With the data on file z1, the command:

pcregrep -o1 '=(.*)' z1

produces:

IN32

On a system like:

OS, ker|rel, machine: Linux, 3.16.0-7-amd64, x86_64
Distribution        : Debian 8.11 (jessie) 
csh - ( /bin/csh, 2016-02-04 )

And more details on pcregrep:

pcregrep        a grep with Perl-compatible regular expressions. (man)
Path    : /usr/bin/pcregrep
Version : 8.35
Type    : ELF 64-bit LSB shared object, x86-64, version 1 ( ...)
Help    : probably available with -h,--help
Repo    : Debian 8.11 (jessie) 

This really has nothing to do with csh , but I ran it under csh to make sure it worked in this instance.

Best wishes ... cheers, drl

2 Likes

Hi,

Thanks for the code. But I am not sure how to use that in my script. Below is my script.

# Common used variables
set IFILE      = "c:/temp/do_info.$$"
set critical_name_file = "c:/temp/critical_name.txt"

set net_path = "C:\temp"

if ( -e $critical_name_file ) then
	set crt_name = (`cat $critical_name_file`)
else
	PAUSE File with netnames not found: $critical_name_file
	exit
endif

set i = 1
set n = $#crt_name
while ( $i < = $n)
    echo $crt_name[$i]

echo "${crt_name[$i]}" >> $name_path/name.txt
    @ i = $i + 1
end

#***EOF***

The input text file contains the following data

#L 0.0468011 3.0767717 0.0885828 3.0767717 r8 P 0 57;Net=SCL
#L -0.0885826 3.0767717 -0.0468009 3.0767717 r8 P 0 102;Net=SDA
#L 0.5317584 -0.0911676 0.5317584 -0.0457404 r8 P 0 495;Net=G4
#L 0.5317584 0.6688324 0.5317584 0.7142596 r8 P 0 496;Net=G4

The output text file should have the following data

SCL
SDA
G4
G4

Let me know how to use code here.

Hi

my five cents

sed 's/.*=//' myFile

and light artillery

grep -o '[^=]*$' myFile
1 Like