Score:0

awk -- duplicating a column and also modifying its text

gb flag
awk {'printf ("%5s\t%s\n", $0, $NF)'} test_VN.txt

works for duplicating a column in a text file however, how can I add _VN before the .jpeg extension of the duplicated column?

For example, I want to have this output:

21_48.jpeg  21_48_VN.jpeg
24_48.jpeg  24_48_VN.jpeg
25_48.jpeg  25_48_VN.jpeg

I want to read the first column from test_VN.txt which only has one column and save it to test_VN_2.txt with two columns.

*Yes, my intention was tab separation between two columns.

Score:4

Use

gsub(/\.jpeg/, "_VN.jpeg", <your string>)

for substring replacement. So you want

awk '{ f=$1 ; gsub(/\.jpeg/, "_VN.jpeg", f) ; printf ("%5s\t%s\n", $1, f) }' test_VN.txt > test_VN_2.txt

You might have used sub as well.

Mona Jalal avatar
gb flag
awesome! this is stellar!
hr flag
`sub` would be sufficient here I think (since only a single replacement per string is required)
sancho.s ReinstateMonicaCellio avatar
@steeldriver - Right. I am simply used to `gsub` (and so I ab-used of it).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.