Get the positional value from first line of the file

Hi,

I have one flat file with delimited field as pipe(|) symbol. The file contains header,detail lines. Header is the first line in the file.

I want to read the value for the position from 15 to 18 in first line of the file.

Pls help me to get the value from position 15 to 18 in first(header) line of the file.

You Can do something like this--

for a single line as header

echo " Hi|Mister|How|Are|You|Doing" | tr -d "|" | cut -c15-18

to raed at a specific position in a file , you can do something like this--

cat filename | tr -d "|" | sed -n '1p' >newfile
cat newfile | cut-c15-18

Thanks
NT

Thanks for your reply.

The file contains signle header row and multiple detail rows.

Is there anyway to get the value(position 15 - 18) from first line of the file without creating new file?

If there is any solution it will really helpful for me.

can try:

head -1 testfile |cut -c15-18

so if you want to assign it to a variable within another script etc. it would be:

var1=`head -1 testfile |cut -c15-18`