Hi Friends
I have a file
like
sample1.txt
------------
10998909.txt
10898990.txt
1898772222.txt
8980000000000.txt
I need to take first 3 characters of each line in a file and i need to print it '
like loop
109
108
189
898
like this
Please help me in this.
Thank you guys
Krish.
Some possibilties:
cut -c 1-3 < sample.txt
or
sed 's/\(...\).*/\1/' sample.txt
awk '{print substr($0,1,3)|' sample.txt
Regards
Another way, you could do the following:
#!/bin/sh
cat sample1.txt | while read FILE
do
SUBSTRING=${FILE:0:3}
echo $SUBSTRING
done
Regards,
Drew
You can also try:
#!/bin/bash
cat sample1.txt| while read line
do
cut -b -3 |tee result.txt
done
Thank you
It help me a lottttttttttttt
Thanks
Krish.
abiinfa
6
What is the solution in other way?
cat file.dat
abcd2342398472394
xyxz430583490583409583409
qwet403985649056834430
need output as:
2342398472394
430583490583409583409
403985649056834430
abiinfa
7
Got the solution.
awk '{print substr($0,5)}' file.dat
-Raveen O.