swasid
1
Hi All,
I have a file test containing a list of rows like:
1222
1323
1424
1525
1626
I want to create a pattern like
100 1222 200
100 1323 200
100 1424 200
100 1525 200
100 1626 200
I am using sed like this but am not able to :
sed "s%.*%/^100 &/,/^200/d%g" test > test1
The & is used to read each record from test
Can you please help?
Use this
awk '{print 100,$1,200}' test >test1
sed 's/.*/100 & 200/' test > test1
Another awk way
awk '{$2=$1;$1=100;$3=200}1' test >test1
Hello,
Here is one more solution, which may help you.
Here is the script named file_name.ksh. Also file_name is the file which have values.
$ cat file_name.ksh
while read line
do
echo 100" "$line" "200
done < "file_name"
Output should be as follows.
$ ksh file_name.ksh
100 1222 200
100 1323 200
100 1424 200
100 1525 200
100 1626 200
$
Thanks,
R. Singh
swasid
7
Is there a way to put a tab in the output file test1 with the following pattern:
The input file test will be like this :
100 1222 200
100 1323 200
100 1424 200
100 1525 200
100 1626 200
The output file test1 should be like this where there is a tab between 100 and 1222
/^100 1222/,/^200/d
/^100 1323/,/^200/d
/^100 1424/,/^200/d
/^100 1525/,/^200/d
/^100 1626/,/^200/d
I tried doing this using my original code where I inserted a tab after 100 and & but when I run it as a script the tab is not working
sed "s%.*%/^100 &/,/^200/d%g" test > test1
awk 'BEGIN{OFS="\t"}{$1="/^"$1;$2=$2"/,/^"$3"/d"}{print $1,$2}' test >test1
swasid
9
Hi,
Just a small change in the input file. The input file test looks like this:
1222
1323
1424
1525
1626
The output file test1 should contain the pattern shown below:
/^100 1222/,/^200/d
/^100 1323/,/^200/d
/^100 1424/,/^200/d
/^100 1525/,/^200/d
/^100 1626/,/^200/d
Use this
awk 'BEGIN { OFS="\t" } {print 100,$1,200}' test >test1
awk 'BEGIN{OFS="\t"}{$2=$1"/,/^200/d";$1="/^100"}{print $1,$2}' test >test1
or
awk '{print "/^100\t" $1 "/,/^200/d"}' test
swasid
12
Hi diehard
The tab should only be after 100 and 1222. Also, the pattern should be same as below
/^100 1222/,/^200/d
/^100 1323/,/^200/d
Did you try the command I provided above in post #11 ?
swasid
14
It's working but strangely when included within a script it's not:(
Have you provided the absolute path for the file test
in your script? Did you receive any error message?