How to remove a string from a text file in shell command? - shell

I have a non.txt file and want to write a shell script to remove a string from the entire file. File has the following data :-
24321,247,654,"^A","91350","JEFFR2",21714,,1,243,654,"^A","91350","JEFFR2",21714,,1,654,0,"P","N","1140828","CA",,,,,"06037","C016","14","7",0,"21714 JEFFERS LN","","SANTA CLARITA","CA","913503917","","","","20140828"
And from the above set of data i want to remove "^A".
Please help me to find out the solution.

Try this:
sed -i 's/"^A"//g' non.txt

Related

Replace an element in a string of csv bash

Working on a bash script. I'm reading a line from a properties file using grep and cut and have fetched some value in a variable role_portions something like this role_portions=role_1:10,role_2:25,role_3:75,role_4:50,role_5:75,role_6:25,role_7:50
Now, I get a few roles as csv input parameter in my bash script and I would want to change those roles values to 0.
For example, when I run modify_script.sh role_2,role_4,role_7, after reading the above value from the file, the script should provide as output role_1:10,role_2:0,role_3:75,role_4:0,role_5:75,role_6:25,role_7:0. Can someone help with this?
When the role names are without special characters (like & and /) you can use sed.
for role in role_2 role_4 role_7; do
role_portions=$(sed -r "s/(^|,)(${role}):[^,]*/\1\2:0/" <<< "${role_portions}")
done
When you are already using grep and cut you might be able to combine commands (maybe use awk).

Replace a sting in shell with special character #shellscripting

Please help me to replace a sting with new updated stinging in multiple files.
Input:
DNEXUS_USERNAME="$(NEXUS_USER_NAME)" -DNEXUS_PASSWORD="$(NEXUS_PASSWORD)"
New string:
DNEXUS_USERNAME_NEW='$(NEW_NEXUS_TKN_NAME)' -DNEXUS_PASSWORD_NEW='$(NEW_NEXUS_TKN)
Issue: when I'm trying to replace the sting by sed command it's being consider as a special character i.e. ($) . please suggest me the correct way to do this task
There doesn't seem to be a need to reference the $ in the file at all:
sed -i 's/NEXUS_USER_NAME/NEW_NEXUS_TKN_NAME/g;s/NEXUS_PASSWORD/NEW_NEXUS_TKN/g' file

Delete a string in a file using bash script

We have a file which has unformatted xml content in a single line
<sample:text>Report</sample:text><sample:user name="11111111" guid="163g673"/><sample:user name="22222222" guid="aknen1763y82bjkj18"/><sample:user name="33333333" guid="q3k4nn5k2nk53n6"/><sample:user name="44444444" guid="34bkj3b5kjbkq"/><sample:user name="55555555" guid="k4n5k34nlk6n711kjnk5253"/><sample:user name="66666666" guid="1n4k14nknl1n4lb1"/>
If we find a particular string suppose "22222222", i want to remove the entire string that surrounds the matched string. In our case the entire portion around 22222222 i.e., <sample:user name="22222222" guid="aknen1763y82bjkj18"/> should be removed and the file has to be saved.
How can we do it? Please help
You can do it using sed utility by invoking it like this:
sed -i file -e 's/<[^<]*"22222222"[^>]*>//'

Implementation issue in cascading while reading data from hdfs

Suppose I have these files in hdfs directory
500/Customer/part-001
500/Customer/part-002
500/Customer/part-003
Can it be possible to check from which part file the tuple is coming?
Note:I have researched but got nothing.
your question is not very clear.
Let's say your output is in following layout and the delimiter is ';'
id;name;age
1;Jordan;22
2;Nathan;33
and so on
You could use awk or grep or both to get the record
for example, if you want to search for the record Nathan, try the file command
grep -r "Nathan" part*
above command will search for the string "Nathan" and if the string is present in any part file then the first entry (word) in output will be the name of the file.
if you don't want the file name you could use
grep -hr "Nathan" part*
Please be more clear when questioning.
I got answer how to get from which part file tuple file are coming.I solved my problem using code below.
String fileName = flowProcess.getProperty("cascading.source.path").toString();
Thanks,

Replacing String Between two special charters in shell script

I am trying to replace a string in my shell script from localhost:7101/RPAS to sound.mojo.com:5555/rpas in my HTML file.
${myDeployment} =<\/td><\td width="0">http://localhost:7101/RPAS<\/td>
My output should be:
${myDeployment} =<\/td><\td width="0">http://sound.mojo.com:5555/rpas<\/td>
The strings that are fixed are ${myDeployment} and </td> and localhost:7101 is not a fixed string.
http://occurs multiple times in document and the above mentioned string occurs at the last , but not at the end of the document.
Is there a way to extend this command to only change the string of the last occurring pattern in the file.
sed -e 's#>http://[^/]*/#>http://sound.mojo.com:5555\/rpas/#' tst.html
Please let me know if there is a way to do it.
You can use this sed command:
sed 's#>http://[^/]*/#>http://sound.mojo.com:5555#' file
${myDeployment} =<\/td><\td width="0">http://sound.mojo.com:5555RPAS<\/td>

Resources