Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Search and replace the last field


 
Thread Tools Search this Thread
# 1  
Search and replace the last field

Hi All,

Seeking for your assistance on how to search and replace the last field/column. please see sample below:

Code:
inputfile1.csv
="8923523434",="543623534"="afd23535623",="100"="200"
="8923523431",="543623536"="afd23535626",="101"="201"
="8923523432",="543623538"="afd23535622",="104"="202"

sample expected output
Code:
inputfile1.csv
="8923523434",="543623534"="afd23535623",="100200"
="8923523431",="543623536"="afd23535626",="101201"
="8923523432",="543623538"="afd23535622",="104202"

it will replace the "=" in the last field of the data.

what i did was:

Code:
awk3=`awk -F "," '{print $4}'  inputfile1.csv | sed -e 's/="//g' -e s'/"//g'`

while IFS=, read a b c d; do
d=$(echo "${awk3}; $d)
echo "$a,$b,$c,$d"
done < inputfile1.csv > final.csv

the problem is it will print the whole records in $d i think due to awk. i don't know else what to do please help.

Please advise,

Thanks,
# 2  
Hello,

Could you please try as follows.



Code:
$  awk -vs1="=" -F"=" '{print $1s1$2s1$3s1$4s1$5$6}' file_name | sed 's/\"\"//g'
="8923523434",="543623534"="afd23535623",="100200"
="8923523431",="543623536"="afd23535626",="101201"
="8923523432",="543623538"="afd23535622",="104202"


Thanks,
R. Singh
# 3  
... or like
Code:
awk -F, 'sub (/"="/, "", $NF)' OFS=, file
="8923523434",="543623534"="afd23535623",="100200"
="8923523431",="543623536"="afd23535626",="101201"
="8923523432",="543623538"="afd23535622",="104202"

 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Search for a value and replace other field in the same set
magnus29
Hello friends, I have huge file with many sets where each "set" has few lines and each set always begins with "Set" in Sq brackets as shown above. # cat file1... Shell Programming and Scripting
2
Shell Programming and Scripting
Search and replace field?
sabercats
I have 2 files A.txt and B.txt A.txt 3 fields and separate by a comma some,thing,florida any1,thing1,california some2,thing2,dallas just,fun,kansas B.txt has 8 fields and separate by a comma what,ever,florida-state,,,,,, some,one,dallas_state,,,,,, You will see 3rd fields are the...... Shell Programming and Scripting
5
Shell Programming and Scripting
Search duplicate field and replace one of them with new value
ezhil01
Dear All, I have file with 4 columns: 1 AA 0 21 2 BB 0 31 3 AA 0 21 4 CC 0 41 I would like to find the duplicate record based on column 2 and replace the 4th column of the duplicate by a new value. So, the output will be: 1 AA 0 21 2 BB 0 31 3 AA 0 -21 4 CC 0 41 Any suggestions...... Shell Programming and Scripting
3
Shell Programming and Scripting
Perl - search and replace a particular field
ramkrix
Hi, I have a file having around 30 records. Each record has 5 fields delimited by PIPE. Few records in the file having Junk characters in the field2 and field4. I found the junk charcter and I tested it and replace the junk with space with the command below perl -i -p -e "s/\x00/ /g"...... Shell Programming and Scripting
1
Shell Programming and Scripting
awk search and replace field
bluejayek
I am writing a c++ program that has many calls of pow(input,2). I now realize that this is slowing down the program and these all should be input * input for greater speed. There should be a simple way of doing this replacement throughout my file with awk, but I am not very familiar with awk....... Shell Programming and Scripting
2
Shell Programming and Scripting

Featured Tech Videos