Hello,
I am a new member here and I am still also fairly new to awk. I am trying to learn and get better but I have a hard time putting everything I want together.
The purpose of the script is to take input date, process it to a standard, and output a new file.
I would like to be able to execute with the following:
# awk -f -v in=INPUTFILE -v out=OUTPUTFILE script.awk
The input file will be setup:
# cat INPUTFILE
"Z","Y","X","W","K"
"AAA","BBB","111555","","A10"
"AAA","10D","A01555","","B10"
I have the command sed 's/\([0-9]\{3\}\)\",\"/\",\"\1/' i can use to move the 3 digit number to the right, but I would like to replace it with awk and have been unsuccessful.
Z replaced with "first"
Y replaced with "second" <----------- {gsub("Y", "second"); print}
X replaced with "third"
W replaced with "forth"
K replaced with "fifth"
after those processes it would look like this.
"first","second","third","fourth","fifth"
"AAA","BBB","111","555","A10"
"AAA","10D","A01","555","B10"
How do I set the top row as their own set of columns separate of the columns below so that I can manipulate header placement as desired?
{printf $5 $1 $2 $3 $4 > out}
{printf $4 $3 $2 $5 $1 >> out} Row > 1 for the data
Row = 1 for headers
Row > 1 for data
final desired output
#cat OUTPUT
"fifth","first","second","third","fourth"
"555","111","BBB","A10","AAA"
"555","A01","10D","B10","AAA"
I can do these one line commands but am not good at putting it together in a functional loop.
This is where I need help, putting it together. I am also unsure of how to go about moving the first row of columns separately of all the other rows.
Thank you in advanced for any guidance I may receive.
I am a new member here and I am still also fairly new to awk. I am trying to learn and get better but I have a hard time putting everything I want together.
The purpose of the script is to take input date, process it to a standard, and output a new file.
I would like to be able to execute with the following:
# awk -f -v in=INPUTFILE -v out=OUTPUTFILE script.awk
The input file will be setup:
# cat INPUTFILE
"Z","Y","X","W","K"
"AAA","BBB","111555","","A10"
"AAA","10D","A01555","","B10"
I have the command sed 's/\([0-9]\{3\}\)\",\"/\",\"\1/' i can use to move the 3 digit number to the right, but I would like to replace it with awk and have been unsuccessful.
Z replaced with "first"
Y replaced with "second" <----------- {gsub("Y", "second"); print}
X replaced with "third"
W replaced with "forth"
K replaced with "fifth"
after those processes it would look like this.
"first","second","third","fourth","fifth"
"AAA","BBB","111","555","A10"
"AAA","10D","A01","555","B10"
How do I set the top row as their own set of columns separate of the columns below so that I can manipulate header placement as desired?
{printf $5 $1 $2 $3 $4 > out}
{printf $4 $3 $2 $5 $1 >> out} Row > 1 for the data
Row = 1 for headers
Row > 1 for data
final desired output
#cat OUTPUT
"fifth","first","second","third","fourth"
"555","111","BBB","A10","AAA"
"555","A01","10D","B10","AAA"
I can do these one line commands but am not good at putting it together in a functional loop.
This is where I need help, putting it together. I am also unsure of how to go about moving the first row of columns separately of all the other rows.
Thank you in advanced for any guidance I may receive.