I’m trying to use sed to show only the 1st, 2nd, and 8th word in a line. The problem I have is that the words are random, and the amount of spaces between the words are also random… For example: Is there a way to get this to output as just the 1st, 2nd, and 8th words: Thanks for any
Tag: sed
How To Substitute Piped Output of Awk Command With Variable
I’m trying to take a column and pipe it through an echo command. If possible, I would like to keep it in one line or do this as efficiently as possible. While researching, I found that I have to use single quotes to expand the variable and to escape the double quotes. Here’s what I was trying: But, I keep
How do I replace a string at an undetermined location in a .txt file with a Shell script?
I’m writing a Shell script using Bash to convert a Robot Framework resource file from Windows to Linux. The contents of the Resource file itself are not important, but here is the required “minimal, complete, and verifiable example”. beep is a typeless empty file used to test a site’s ability to upload files. There will be an unspecified and ever-changing
Linux cut, paste
I have to write a script file to cut the following column and paste it the end of the same row in a new .arff file. I guess the file type doesn’t matter. Current file: The output should be: how can I do this? using a Linux script file? Answer Brief explanation, ^([^,]*) would match the first field which separated
Replace text between two lines with contents of a file stored in a variable in sed
Let’s say I have a file called original.txt with this content: red blue water food tree gray white Also I have a file called new.txt with this content: green black yellow purple Now I want to write a script that replaces the lines between blue and gray in original.txt with the contents of new.txt, so it gives me this result:
How to replace lines that contains integers by using sed
I have a file that contains two fields. The first field may or may not contain an Integer. If it contains an integer and a dot follows the integer I would like to manipulate part of second field. So As an example: I couldn’t make it since I have very limited knowledge in regex. I would be very appreciate if
Why Sed cannot replace lines that contains . + and *
I have a large file and some of the lines are as follows: I want to replace ….+UNKNOWN part with the …+PUNCT To do that, I did the following: However, none of the lines gone. I couldn’t find my error, could you help me about ? Answer In some versions of sed, + has a special meaning, use + to
free -g with sed -n plus nth character
I am trying to create a script to display just one of the numbers from the free command. In my case, the number I want is on the 2nd line of the free -g output and at character slot 43. The original output of free -g is: So far I have gotten the 2nd line to display with: I need
Capture a set of numbers in sed
I have the following string I am trying to capture only v2010.0_1.3 using and I get the following result v2010.0_1.3 Tue Jun 6 14:38:31 PDT. It looks like sed is not stopping the first occurrence of the space, but at the last one. How can I capture only until the first occurence? Answer Using sed sed’s regular expressions are “greedy”
sed command to copy lines that have strings
I want to copy the line that have strings to another file for eg A file contain the below lines I want to copy the lines that has 100 or 200 to another file by skipping all the characters before (first occurrence in a line)100 or 200 I want it to copy 100 50 200 40 100 34 to another