I am trying to replace an entire description string contained in an XML file. I would like to replace that string with a variable. I am using a SED command within a Groovy script. I have the following code. I am expecting the string “foo” to replace the description text but it doesn’t. Instead the following line causes the XML
Tag: sed
How to replace a word in a file with a word in another file in Linux
I want to change a word in a file, with another word that I get from another file. Let’s say I have 2 files : File #1 contains : jack File #2 contains : Hello name How can I replace the word “name” with “jack”? PS. File #1 contains only this word, no need for any regex. Answer This shell
Using SED to convert sensors command output to a loggable entry
Consider the following sensor command output: I’m trying to turn this into a log entry, like this, where the “temp1” values are placed next to the PCI adapters, and the board (it8721-isa-0290): I think sed is the correct tool for this, but if it’s not please let me know. I have already trimmed some data out using 2 sed commands,
How to grep string and show previous word in a Linux file
i have a file with a lot of IPs and each IP have an ID, like this: Below this Ips and after these Ips the file have more information, its a output to an API call.. I need, grep a IP and then the command shows the id, just the number. Like this: EDIT: More information, the ip will be
How to add text at the end of each line after skipping Last N characters
I’m on Linux command line and I have log file with following content I want to add date before Time Stamp for every line Answer Something like this: sed -r “s/([0-9]+{1}:[0-9]+{1}[A-Z]{2}.*$)/01 Oct 2016 1/g” test.txt > new.txt Where text.txt is your log file and “01 Oct 2016 ” is your text and the 1 is the time inserted back in
getting the output of “find” in a CSV
I’ve got a project where I’m trying to collect all the files on a linux system into a CSV to be dumped into a DB. my script has But the problem is that I have filenames %f and directory names %h with commas in them. So then I thought I could just put each item in quotes and that won’t
How to remove certain lines of a large file (>5G) using linux commands
I have files which are very large (> 5G), and I want to remove some lines by the line numbers without moving (copy and paste) files. I know this command works for a small size file. (my sed command do not recognize -i option) This command takes relatively long time because of the size. I just need to remove the
How To Delete A File Every X Times A Script Is Run – Manage A Log File From Inside A Script?
I would normally just schedule this as a cron job or script, however, I would like to delete a log file (it’s constantly appended to every time a script runs) only after 50 times. Needed Inside The Script: The thing is, since the script does not run consistently, it has be to be implemented within the script itself. Please note:
How to edit a particular line and replace text via sed in linux (cent os)
Width : 1 280 pixels Height : 720 pixels I’m working on a bash script and need to filter video on the bases of resolution. Like If Width is greater than equal to 1280 then HD else Non HD I’m using mediainfo to make and save info in txt file. output of this is 1 280 this is because of
Unable to parse bash output using regex and collect a part of it
I am trying to parse out the recent load, from the output of this command – The first one after the load average: – I was using this, which worked – However, I realised that the value I am looking for may not always be the 10th variable. Hence I am trying to use regex here, but unfortunately, not able