Domanda

Using awk, how can i redirect the data to all files in the directory?

like ,lets say i want to redirect to file.txt i will do:

echo "abc"|awk '{print >"file.txt"}'

how can i acheive the same thing but to multiple files(in fact all files) in the directory. there are some .txt files in teh cirrent directory. so i want to redirect abc to all the files in the current directory which have an extension of .txt.

È stato utile?

Soluzione

echo abc|awk '{print |"tee files"}'

Altri suggerimenti

You can use tee:

echo "abc" | tee files/*

If the directory with all these files are in /files/.

One way using GNU awk:

awk -v str="abc" '{ print str > FILENAME; nextfile }' *.txt

This command will overwrite all the content of all files with txt extension with the string abc. You will need the GNU version because of the nextfile instruction, that closes current file and begin to process the next one.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top