AWE
AWE

Reputation: 4135

Piping sed to cat via xargs?

I have three files like this:

haeder
line

I write this:

sed '1,1d' */*filename*.txt | xarg cat > crap4.txt

and expect this:

line
line
line

but I get "cat: line: No such file or directory"...

Upvotes: 1

Views: 839

Answers (4)

AWE
AWE

Reputation: 4135

This is what worked perfectly:

array=(*somestring*.txt)
for i in {0..2}; do
sed '1d' ${array[$i]} >> crap4.txt;
done

Bash to the rescue.

Thanx for the help.

Upvotes: 0

potong
potong

Reputation: 58483

This might work for you (GNU sed):

sed -s '1d' */*filename*.txt > crap4.txt

The -s switch treats each file separately rather than the default which is as one continuous stream.

Upvotes: 3

Dylan Northrup
Dylan Northrup

Reputation: 161

This is a useless use of cat (as defined by Randal Schwartz). Using plain redirection works. If you really wanted to use cat, you'd want to remove 'xargs' and use '-' as an argument to cat. Here's an example to print all of the names from /etc/hosts

myhost> awk '{print $NF}' /etc/hosts | cat -
localhost
myhost

hosts
ip6-loopback
ip6-localnet
ip6-mcastprefix
ip6-allnodes
ip6-allrouters
ip6-allhosts

But using '>' instead and getting rid of the 'cat' is probably your best choice here.

Upvotes: 1

Charlie Martin
Charlie Martin

Reputation: 112386

That's because sed is sending the contents of those edited files out. The first argument cat gets is the first line of the edited file.

You're making it too complicated, you want

sed '1,1d' */*filename*.txt > crap4.txt

Upvotes: 2

Related Questions