Follow

How can I do with bash
echo "line1 from file2" >> echo "line1 from file1"
?

· · Web · 3 · 0 · 1

I got a better one:
for run in {1..x}; do sed -n "$run,${run}p" file1 >> `sed -n "$run,${run}p" file2`;done

@matrix Not sure if I understand it correctly. You have one file with lines and one with filenames and you want to write line from first file with name from the second file?

@matrix seq `wc file1 | awk -c '{print $1}'` | parallel -- 'sed -n {}p file1 >> `sed -n {}p file2 | tr -d "\n"`'

@matrix not sure if I understand you perfectly but
head -n 1 file2 >> `head -n 1 file1`
@matrix equivalent syntax (these brackets are nestable):
head -n 1 file2 >> $(head -n 1 file1)

@matrix how about:

i=1;<file1 while read l; do echo $l >> $(sed "${i}q;d" file2); i=$[i+1]; done

Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.