Reputation: 7800
I have a file (myfile.txt
) that contains these lines:
foo
bar
qux
In a bash script I'd like to add a value on the string resulting in
foo 1000
bar 1000
qux 1000
I tried this but failed.
#!/usr/bin/bash
MYVAL="1000"
cat myfile.txt | xargs -I '{}' echo {} & echo $MYVAL
which only prints 1000 on one line.
Upvotes: 2
Views: 1473
Reputation: 6345
Your attempt is almost there:
$ xargs -I{} echo {} 1000 < file6
boo djhg 1000
bio jdjjf 1000
dgdhd bgo 1000
ghhh 1000
baao biologico bata 1000
baa beto biologic 1000
bojo bija 1000
Upvotes: 1
Reputation: 43089
You can use sed
and you don't really need a pipe for this:
myval="1000"
sed "s/$/ $myval/" file > file.modified
for in-place editing:
sed -i "s/$/ $myval/" file
s/$/ $myval/
- places a space followed by the value of $myval
at the end of each lineMore about sed
here: http://grymoire.com/Unix/Sed.html
Upvotes: 4