Skip to content
Advertisement

Tag: sed

How can I show only some words in a line using sed?

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

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

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

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

Advertisement