ust
1
I have a file as below,
$vi myfile
aaa;20071217
bbb;20070404
ccc;20070254
"
if I want to cut the column 9-12 of the first line , the output should be 1217 , can advise how to write a script to get the result ? thx
p.s. can a script that have only ONE line could do that ?
echo 'aaa;20071217' | sed 's/.*\(....\)/\1/'
Simply:
cut -c 9-12
or:
awk '{print substr($0, 9, 4)}'
Regards
<prompt>$ cut -b 9- myfile > cutfile
<prompt>$ cat cutfile
or
<prompt>$ cat myfile | cut -b 9-
ust
5
thx reply ,
I tried it , the result is as below,
1217
0404
0254
if I only want the get the date in FIRST line , the result is 1217 , can advise how to modify the script ? thx
awk 'NR==1{print substr($0, 9, 4);exit}'
Regards