basic cat replace string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting basic cat replace string
# 1  
Old 02-16-2007
basic cat replace string

trying to exclude hostnames ending in "s" from a host file:

Code:
# cat hosts
ssef
ssefd
ssefsfff
ssefsfs
# for x in `cat hosts`; do echo "${x/*s}" ;done
ef
efd
fff

#


How can I echo/or not echo only 'ssefsfs' ??

thanks
# 2  
Old 02-16-2007
Code:
 sed -n "/s$/! s/s.*s//p" file

To print lines ending with s
Code:
sed -n "/s$/p" file

To print lines without s at end
Code:
sed -n "/s$/! p" file

# 3  
Old 02-16-2007
Quote:
Originally Posted by anbu23
Code:
 sed -n "/s$/! s/s.*s//p" file

To print lines ending with s
Code:
sed -n "/s$/p" file

To print lines without s at end
Code:
sed -n "/s$/! p" file

thanks, exactly what i need
# 4  
Old 02-19-2007
with awk,

Code:
awk '{ if( substr($0, length, 1) !~ /s/ ) { print } }'  filename

# 5  
Old 02-19-2007
Erm.... grep Smilie

Code:
 grep '[^s]$' hosts

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to append a string by cat and redirect to other file?

Hi, when I do cat for kernel parameters cat /proc/sys/kernel/sem >> /etc/sysctl.conf 4096 4096 32 128 The above command working with out any doubt but I want to pass it like below, need to append "kernel.sem =" and pass it to /etc/sysctl.conf kernel.sem = 4096... (2 Replies)
Discussion started by: stew
2 Replies

2. Shell Programming and Scripting

Replace cat and grep with <

Hello someone told me to use OS=`awk '{print int($3)}' < /etc/redhat-release` instead of OS=cat /etc/redhat-release | `awk '{print int($3)}'` any idea for the reason ? (5 Replies)
Discussion started by: nimafire
5 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

replace cat huge_multiplefiles |sort |uniq -c

Does any one know any command runs faster than this to give duplicate numbers cat file1 file2 ....file 100 | sort |uniq -c thanx (3 Replies)
Discussion started by: quincyjones
3 Replies

5. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

6. UNIX for Advanced & Expert Users

The best way to skin a cat OR how do I get file system info on the most basic level?

Hi, We have an FTP server (vsftpd) running on Linux, that I've kinda built a "Data Management" system around. I could use some ideas as to the best way to handle/create "triggers" for file notifications. Internal users drag 'n drop files from their Windows boxes to the server via Samba... (2 Replies)
Discussion started by: mph
2 Replies

7. Shell Programming and Scripting

Have a basic 'for i in cat list' - Trying to get i to be set to a name with a space

Hi Have a file called ldap.list: ****** "o=unix forum" o=groups ****** i wrote a basic script that runs: for i in `cat ldap.list` do ldapsearch -h host -p 389 -b $i THE PROBLEM: - It looks like when the for i in cat ldap.list runs, it doesn't seem to care about the " ", it... (2 Replies)
Discussion started by: littlefrog
2 Replies

8. UNIX for Dummies Questions & Answers

got a basic doubt on cat-file permissions

Hi all, Today I was just fooling around with directories and faced this. I create a directory 'testdir' and create a file 'myfile' inside it. gandalf@gondor:~$ mkdir testdir gandalf@gondor:~$ cd testdir gandalf@gondor:~/testdir$ touch myfile Then I set the following permissions for the... (7 Replies)
Discussion started by: ranj@chn
7 Replies

9. Shell Programming and Scripting

Basic sed replace question

Hello, I have a .htaccess file as follows... No I want to comment the last line ( in this case.. it may not be a last line for other cases).. please advise how to add a # (comment infront of "Options All -Indexes" not assuming this line to be the last line using sed. root@server1 # cat... (13 Replies)
Discussion started by: fed.linuxgossip
13 Replies

10. Shell Programming and Scripting

variable= 'cat file|wc -l' String problems

Hi, does anybody knows about wc -l, how to transform it inot a just number? this script ALWAYS executes the command3!!, However, the value of BMU_RUNNING is 1 case $BMU_RUNNING in *0) command1 ;; *1) command 2;; *)command 3;; esac The... (3 Replies)
Discussion started by: Santiago
3 Replies
Login or Register to Ask a Question