as title said, Im trying to change only the first occurrence of word.By using
sed 's/this/that/' file.txt
though i'm not using g option it replace entire file. How to fix this.?
UPDATE:
$ cat file.txt
first line
this
this
this
this
$ sed -e '1s/this/that/;t' file.txt
first line
this // ------> I want to change only ...
how to delete all lines below a word except last line in a file. suppose i have a file which contains
| 02/04/2010 07:24:20 | 20-24 | 26 | 13 | 2.60 |
| 02/04/2010 07:24:25 | 25-29 | 6 | 3 | 0.60 |
+---------------------+-------+------------+----------+-------------+
02-04-2010-07:24 --- ER...
I have
1 LINUX param1 value1
2 LINUXparam2 value2
3 SOLARIS param3 value3
4 SOLARIS param4 value4
need by awk to pring all lines that $2 is LINUX
THX
...
I've the CSS file with many entry like
#id1, #id2, #id3, #id4 { ... }
#id3, #id2 { ... }
#id2, #id4 { ... }
I want to extract list of unique IDs using command line tools (msys).
Unique means any entry in list presented only once. How?
PS: I know how doing it using python, but what about awk/sed/cat?
...
In a file 4th column contains a floating point numbers
dsfsd sdfsd sdfds 4.5 dfsdfsd
I want to delete the entire line if the number between -0.1 and 0.1 (or some other range).
Can sed or awk do that for me?
thanks
...
I have a for loop to get the list of PID's and kill each PID. I want to display the entire line of PS output and write it to the /tmp/outfile . But from each line of PS output each field(PID,PPID,...) is written along with a new line in the /tmp/outfile. So if PS output has three lines as output i want to log these three lines into ...
I want to replace every instance of int in a very large codebase with int32_t, for portability reasons. I have unsuccessfully tried :
sed s/'\bint\b'/' int32_t '/g
and it fails to match instances where the int is the first thing on the line. I am completely at a loss for how to make it match then.
Any ideas?
...
Hey
I'm having hard time selecting from a file using a regular expression. I'm trying to replace a specific text in the file which is full of lines like this.
/home/user/test2/data/train/train38.wav /home/user/test2/data/train/train38.mfc
I'm trying to replace the bolded text. The problem is the i don't know how to select only the bol...
I have a file with two columns,
sdfsd 1.3
sdfds 3
sdfsdf 2.1
dsfsdf -1
if x is 2
I want to print sdfsdf 2.1
How to express it in awk (bash or sed is fine too)
...
I have nested subdirectories containing html files. For each of these html files I want to delete from the top of the file until the pattern <div id="left-
This is my attempt from osx's terminal:
find . -name "*.html" -exec sed "s/.*?<div id=\"left-col/<div id=\"left-col/g" '{}' \;
I get a lot of html output in the termainal, but no f...
I'm trying to remove a case clause from a bash script. The clause will vary, but will always have backslashes as part of the case-match string.
I was trying sed but could use awk or a perl one-liner within the bash script.
The target of the edit is straightforward, resembles:
$cat t.sh
case N in
a\.b);
#[..etc., varies]
;;
...
Hello.
I believe this may be a simple question, but I've looked everywhere and tried some workarounds, but I still haven't solved the problem.
Problem description:
I have to replace a character inside a file and I can do it easily using the command line:
sed -e 's/pattern1/pattern2/g' full_path_to_file/file
But when I use the same l...
I am using sed to extract parts of an XML I am interested in:
sed '/<car car_id="BMW" year="1999"/,/</car>/p' input
So what I really would like to get back is:
<car car_id="BMW" year="1999" color="blue> ... </car>
Instead I get back a bunch of other car elements.
...
I'm using regex to parse NMAP output. I want the ip addresses which are up with the corresponding ports open. Now I've a very naive method of doing that:
awk '/^Scanning .....................ports]/ {print substr ($2,1,15);}' results.txt
awk '/^[0-9][0-9]/ {print substr($1,1,4);}' results.txt | awk -f awkcode.awk
where awkcode.awk con...
So i have a 1 long line with characters, for example numbers[1-1024] in one line(no "\n", "\t" and "\b"):
1 2 3 4 5 6 7 8 9 10 11 ... 1024
How do i extract and print characters for example exactly 55 characters after 46? So output would be:
47 48 49 ... 101
Thanks.
...
hi
param can be one
of the following
a,b , f, d
or
a, b , c, e
or
r , q ,c , d
but we want a,b,c,d without spaces
for example if we get: a , b ,c,d
need to change it to a,b,c,d
sytax to do that
yael
what the best sed syntax to change it
...
Dear all,
I have an input file with a list of movies (Note that there might be some repeated entries):
American_beauty__1h56mn38s_
As_Good_As_It_Gets
As_Good_As_It_Gets
_DivX-ITA__Casablanca_M_CURTIZ_1942_Bogart-bergman_
Capote_EN_DVDRiP_XViD-GeT-AW
_DivX-ITA__Casablanca_M_CURTIZ_1942_Bogart-bergman_
I would to find the corresponding...
hi
I have the following file
How to remove by sed all FILE NAME lines except the first uniq FILE NAME
For example need to remove all FILE NAME lines from the file except the first:
FILE NAME: /dir1/dir2/dir3/dir4/dir5/file
FILE NAME: /dirA/dirB/dirC/dirD/dirE/file
the file:
FILE NAME: /dir1/dir2/dir3/dir4/dir5/file
PARAMETER NAME: ...
How to shutter the "#" characters to one "#" char by sed ?
From:
param=## ### ff ## e ##44
To:
param=# # ff # e #44
...
I couldn't find an answer for this exact problem, so I'll ask it.
I'm working in Cygwin and want to reference previous commands using !n notation, e.g., if command 5 was which ls, then !5 runs the same command.
The problem is when trying to do substitution, so running:
!5:s/which \([a-z]\)/\1/
should just run ls, or whatever the arg...