in Education by
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago. Improve this question I have a file called names.txt that looks like: 0,james,hard,fun,circle 1,caron,hard,agin,square And I want to make it end up like: james,hard,fun,circle,c0 caron,hard,agin,square,c1 I would like to run a script that asks for the file , and then make those changes to the file using the $1 argument and cut. I know this is a hard question that may involve alot of code, so I truly appreciate your guys help. NOTE: my file contains 9999 inputs and starts with first one being 0 , so 10,000 in total entry's. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Here's a complete file that will modify the file in the way you ask and write It to the terminal, specifically to standard out, which is one of the "channels" that gets written to your terminal by default. (channel is not a technical term). #!/bin/bash awk -F, -vOFS=, '{print $0,"c" $1 }' "$1" | cut -d, -f2- If the data contains blank lines in it, we can skip over them by adding a check in the awk fragment. #!/bin/bash awk -F, -vOFS=, 'NF > 0 {print $0,"c" $1 }' "$1" | cut -d, -f2- If the file is named rotate.sh and your data whatever.csv, you can invoke is as bash rotate.sh whatever.csv This will print the modified file to your terminal. If you want to save it somewhere, write this. bash rotate.sh whatever.csv > /tmp/a.csv Do not write the following bash rotate.sh whatever.csv > whatever.csv The script above is not capable of modifying the same file it is reading from. The example sed script provided by @lurker will work on Linux. If you type this into the command line literally, it will modify the file in place. sed -i "s/^\([0-9]*\),\(.*\)$/\2,c\1/" whatever.csv The OS X equivalent of that command is sed -i '' "s/^\([0-9]*\),\(.*\)$/\2,c\1/" whatever.csv

Related questions

0 votes
    This question already has answers here: Why doesnt "tail" work to truncate log files? (6 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Why doesnt "tail" work to truncate log files? (6 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Why doesnt "tail" work to truncate log files? (6 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    What is the best way to open a file as reading/write if it exists, or if it does not, then create it and ... to do the opening part. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    This is obviously a stupid question. I am coding in Eclipse both on Mac and Linux, but I mixed up ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 22, 2022 in Education by JackTerrance
0 votes
    I use nonblocking socket to receive new connection. But the code repeatedly fails to accept(). int sockfd = ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 6, 2022 in Education by JackTerrance
0 votes
    For instance, given ( 1, 2, 5, 6, 7), i'd like to determine that 3 and 4 are missing? ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    Installed Postgres-XC $>sudo apt-get install postgres-xc then $ postgres -V postgres (PostgreSQL) 9.2. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    For instance, given ( 1, 2, 5, 6, 7), i'd like to determine that 3 and 4 are missing? ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    fairly new to using linux on shell. I want to reduce the amount of pipes I used to extract the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    in the source directory, i have some binary files named 1.bin, 2.bin, 3.bin, etc. In the dest ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    We currently use multiple web servers accessing one MySQL server and fileserver. Looking at moving to the cloud, ... another solution? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
...