logo
down
shadow

how to replace a string at a specific position in a csv file using bash


how to replace a string at a specific position in a csv file using bash

By : Dipra Chakravorty
Date : November 28 2020, 01:01 AM
around this issue Using sed, you can also direct that only the 4th field of a comma separated values file be changed to "ZZ" for lines beginning "AA" with:
code :
sed -i '/^AA/s/[^,][^,]*/ZZ/4' file
$ cat file
AA,1,CC,1,EE
AA,FF,6,7,8,9
BB,6,7,8,99,AA
$ sed '/^AA/s/[^,][^,]*/ZZ/4' file
AA,1,CC,ZZ,EE
AA,FF,6,ZZ,8,9
BB,6,7,8,99,AA


Share : facebook icon twitter icon
Using bash, how do I find all files containing a specific string and replace them with an existing file?

Using bash, how do I find all files containing a specific string and replace them with an existing file?


By : Rubyredriots
Date : March 29 2020, 07:55 AM
I hope this helps . I am using Linux and would like to replace all files containing the string 000000 with an existing file /home/user/offblack.png but keep the existing filename. I've been working at this for a while with various combinations of -exec and xargs but no luck. So far I have:
code :
find . -type f | grep 000000 | tr \\n \\0 | xargs -0i+ cp ~/offblack.png "+"
How to replace a string in a file only if the line containing it does not also contain a specific string using Bash?

How to replace a string in a file only if the line containing it does not also contain a specific string using Bash?


By : Sambhudatta Samal
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I would like to replace all instances of target with replace in the following file.csv using Bash, but only if the line containing it does not also contain the string skipline:
code :
% sed '/skipline/!s/target/replace/g' input
abc,abc,keepline,replace,abc,abc
abc,abc,skipline,target,abc,abc
bash replace string in file with specific index

bash replace string in file with specific index


By : Jean Saba
Date : March 29 2020, 07:55 AM
wish of those help Note, id attribute value from replace.xml should match any of the entries from idfile.txt to fit the condition.
Awk + paste solution:
code :
awk -v ids="$(paste -s -d'|' idfile.txt)" 'match($2,ids){ sub("online","offline",$1) }1' replace.xml
<condition="offline" id="1111" >
<condition="online" id="2222" >
<condition="offline" id="3333" >
<condition="offline" id="4444" >
Bash - Search for a specific string in a file and replace with immediate source

Bash - Search for a specific string in a file and replace with immediate source


By : user1812292
Date : March 29 2020, 07:55 AM
Hope that helps I am trying to search for the string "missing" in a file containing the following: , You can try this (write this in something.awk):
code :
{
    if($0 ~ "<source>"){
            source = gensub(/.*<source>(.*)<\/source>.*/, "\\1", "", $0)
    }
    if($0 ~ "<translation>missing"){
            $0 = gensub(/>.*</, ">" source "<", "", $0)
    }
     print
}
awk -f something.awk filelocation
<message>
    <source>TypeA</source>
    <translation>TypeA</translation>
</message>
<message>
    <source>TypeB</source>
    <translation>TypeB</translation>
</message>
<message>
    <source>TypeC</source>
    <comment>Context menu</comment>
    <translation>TypeC</translation>
</message>
How can I replace a specific character in a file where it's position changes in bash command line or script?

How can I replace a specific character in a file where it's position changes in bash command line or script?


By : user3628002
Date : March 29 2020, 07:55 AM
this will help I have the following file: , With GNU awk
code :
$ cat file
2020-01-27 19:43:57.00 C M -8.5 0.2 0 4 81 -2.9 000 0 0 00020 043857.82219 3 1 1 1 1 1

$ gawk -i inplace -v new=9 'NF {$(NF-5) = new} 1' file

$ cat file
2020-01-27 19:43:57.00 C M -8.5 0.2 0 4 81 -2.9 000 0 0 00020 043857.82219 9 1 1 1 1 1
Related Posts Related Posts :
  • Debug tcl flow - like bash -
  • Security of su root in bash script
  • how to delete duplicate lines in a text file in unix bash?
  • Compare a variables in bash
  • How do I use sed on a string?
  • Using bash variables for range in sed
  • convert a DURATION HH:MM:SS to seconds in bash
  • Shell make system paths click-able when printed out by my shell script
  • I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements
  • AWK between 2 patterns - first occurence
  • Nginx on docker - daemonize and attach to bash
  • Delete or Replace nth line in a file after a pattern match using shell scripts
  • Actual return code for SCP
  • How to exit a bash function that expects a return
  • Bash script to split file into two files while changing output file during processing
  • Pass command line arguments via sbatch
  • variable substitution (what do you call/name this method)?
  • Call function from another shell script
  • How to Grep and Replace With Exclusions
  • shell command to remove characters after a special character in bash/shell
  • How do I run a script for 1st working day of every month in cron?
  • Bash Unexpected End of File Error After Installing RVM
  • Nested Loop with increment on inner loop?
  • video orientation detection in bash
  • Interrupt sleep in bash with a signal trap
  • Want file rename script to add number at end with fixed length
  • What's the DRYest way to replace a file with a symlink in bash
  • How to run Bitcoin's autogen.sh file?
  • Renaming files in folder and subfolders using a list- Bash Script/Unix
  • Bash command to compare more than two files
  • If It is a directory append text
  • What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org