Input new values into a column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Input new values into a column
# 1  
Old 04-14-2010
Input new values into a column

Hi

I would like to change certain columns in a file depending on the users choice of input and which columns they would like to change.

Here is my csv file:

Code:
 
SITEID,CELLID,Access Grant Blocks Reserved
1,1A,5
1,1B,2
1,1C,3
2,2A,7
2,2B,4
2,2C,0

If for example they would like to change the first record, third field, or add a fourth field, how can this be done? If they add a fourth field, they have to be allowed to enter values for the fourth field for all records.

This is what I have which inly allows them to change the third field by entering the cellid for the second field.

Code:
awk -F, -v id=$id -v paramval=$paramval -v paramname=$paramname -v oldfile=$dsxdir/$oldfile -v newfile=$dsxdir/$newfile '$2==id{$3=paramval}1' OFS="," $dsxdir/$oldfile > $dsxdir/$newfile

so " id " represents all the cellid's and "paramval" represents the values

I dont know how to manipulate this csv file.

Thank you for your help.

---------- Post updated at 08:22 AM ---------- Previous update was at 08:17 AM ----------

Can I simplify this please, suppose I want to only alter the first record, third field only if the user enters a value for paramname, and if they don't, this will remain as is. Remember, it means that no cellid will be entered in this instance.
# 2  
Old 04-14-2010
your input here doesn't clear what user is presented with and what options are there for the user to change.

Do you really present the file as such without any hint and then user change it on his/her own?

If you can simulate some session that you would like to be done, it may help me to do so for you..

looks like you are doing the GSM Stuff Smilie

Regards,
busyboy.
# 3  
Old 04-14-2010
Smilie Yip .. GSM - you do your stuff well ....

Okay well basically, it's just scripts thats I'm creating to automate some testing.

So there are scripts in one directory and csv files in another.

Here the help function tells the user their options:

Code:
function displayHelp()
{
echo ""
echo " Usage: ./Import_PlannedCELL.sh [ -c -d ]"
echo ""
echo " -c, --csvfile identified by the input file in csv format "
echo " -d, --dsxfile identified by the output file in dsx format "
echo " -h, --help identified by the help menu "
echo ""

}

so the user types ./script -h and is told how the script should be called .. that is

Code:
 
./script -c csvfilename -d dsxfilename

The script looks for the csv file from the specified directory and converts it to a dsxfile and stores it another directory. The user does not have to specify directory paths.

This part works fine.

Now I need the script to output the help function when nothing is entered when calling the script. It does so if any other character is entered except the ones specified in getopts ( c , d , h ):

Code:
 
while getopts " c: d: h " option
do
case $option in
c ) csvfile="$OPTARG";;
d ) dsxfile="$OPTARG";;
h ) displayHelp;exit;;
? ) displayHelp;exit;;
* ) displayHelp;exit;;

esac;
done

How do I get it to display help in this case:

Code:
./script

Thank you

---------- Post updated at 09:32 AM ---------- Previous update was at 09:29 AM ----------

Oooops, this is for my previous thread ... it still doesn't work .....

Sorry for the confusion.Smilie
# 4  
Old 04-14-2010
To do add, change and delete to a csv file using a shell script is asking a lot. Why not use MS Excel and save the spreadsheet as a csv file on the unix system
# 5  
Old 04-14-2010
Hi

It would have been nice if I could. Unfortunately, requirements stipulate that this is how it must be done.

I was able to change values by allowing the user to input the cellid, and then search for the cellid, and change the corresponding paramvalue

Code:
 
'$2==id{$3=paramval}1'

what if the user decides to change the parameter name?

so I need to cater for that.

I appreciate your reply, if this is impossible, I understand.
# 6  
Old 04-14-2010
Which Operating System are you using (brand and release number)?
# 7  
Old 04-14-2010
Hi. Can you give several examples of the input data for request modifications?

I think it is possible, at least the way I understand it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

2. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

3. UNIX for Dummies Questions & Answers

Match sum of values in each column with the corresponding column value present in trailer record

Hi All, I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record. For example, let's assume for column D... (9 Replies)
Discussion started by: tpk
9 Replies

4. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

5. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Converting odd values to even values(or vice-versa) located in a column

Hello All, I have a below data in a .csv file where all rows where col1 is A, col2 is odd numbers, similarly even numbers for all rows where col1 is B. Note that my data has some other columns(not shown here) too (around 100) after col2. Tool,Data A,1 A,3 A,5 .... so on B,2 B,4 .... ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

7. UNIX for Dummies Questions & Answers

shift values in one column as header for values in another column

Hi Gurus, I have a tab separated text file with two columns. I would like to make the first column values as headings for the second column values. Ex. >value1 subjects >value2 priorities >value3 requirements ...etc and I want to have a file >value1 subjects >value2 priorities... (4 Replies)
Discussion started by: Unilearn
4 Replies

8. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

9. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

10. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies
Login or Register to Ask a Question