How to remove first word?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove first word?
# 1  
Old 12-24-2013
How to remove first word?

Hi All,

I want to remove the first word "cn=" from the below details. Only I want the number like 171345,174144...

Code:
cn=171345
cn=174144

How can I achieve this.

Please suggest.

Thanks-
P
# 2  
Old 12-24-2013
Hello,

Here are the 2 solutions.


1st way:
Code:
awk -F"=" '{print $2}' file_name
171345
174144

2nd way:
Code:
sed 's/[a-z]//g;s/[[:punct:]]//g' file_name
171345
174144


Adding one more way to same:
3rd way:
Code:
awk -F"=" '{if($NF ~ /[0-9]/) print $NF}' file_name
171345
174144

Thanks,
R. Singh

Last edited by RavinderSingh13; 12-24-2013 at 06:09 AM.. Reason: Added 3rd way to get the answer for same..
# 3  
Old 12-24-2013
Code:
sed 's/cn=//'

# 4  
Old 12-24-2013
Hello,

One more approach.


Code:
awk '{gsub(/[a-z]/,X) gsub(/[[:punct:]]/,Y);print}' file_name
171345
174144

EDITED:
One more approach for same. Smilie

Code:
sed 's/\(.*=\)\(.*\)/\2/g' file_name

Output will be as follows.

Code:
171345
174144



Thanks,
R. Singh

---------- Post updated at 07:33 AM ---------- Previous update was at 06:21 AM ----------
# 5  
Old 12-24-2013
Some more Awk :

Code:
$ cat <<test | awk 'gsub(/.*=/,x)'
cn=171345
cn=174144
test

171345
174144

$ cat <<test | awk -F"=" '$0 = $NF'
cn=171345
cn=174144
test

171345
174144

$ cat <<test | awk '$1 = substr($1,4)'
cn=171345
cn=174144
test

171345
174144

$ cat <<test | awk -F"=" '{print $NF}'
cn=171345
cn=174144
test

171345
174144

# 6  
Old 12-24-2013
Hi.
Quote:
Originally Posted by pokhraj_d
... Only I want the number like 171345,174144...
Code:
grep -o '[0-9]*' <<EOF
cn=171345
cn=174144
EOF
171345
174144

Best wishes ... cheers, drl
# 7  
Old 12-25-2013
I forgot to post one more easiest solution yesterday here is that
Code:
$ cat <<test | tr -cd '[0-9]\n'
cn=171345
cn=174144
test

171345
174144

for file use like this
Code:
$ tr -cd '[0-9]\n' <file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove everything after a word containing string?

Hello, I wish to remove any word coming after searched string found in a word. source*.txt #!bin/bash #test1 http://www.aa.bb.cc http://www.xx.yy http://www.11.22.44 #test2 http://www.11.rr.cd http://www.01.yy http://www.yy.22.tt #test3 http://www.22.qq.fc http://www.0x.yy... (15 Replies)
Discussion started by: baris35
15 Replies

2. Post Here to Contact Site Administrators and Moderators

Please remove the word from posts

Hi Sir, Need your help in removing the following words from the posts . These are confidential info posted by mistake and our organization is doing an audit on this. Could you kindly remove as per below. https://www.unix.com/shell-programming-and-scripting/197017-perl-help.html ... (4 Replies)
Discussion started by: ptappeta
4 Replies

3. Shell Programming and Scripting

Remove word before a character

Hi, I have a file which looks like this id integer, name string, create_dt date, I want to remove all words that are present before the character , My output should be id, name, create_dt, Thanks wah (2 Replies)
Discussion started by: wahi80
2 Replies

4. Shell Programming and Scripting

Remove word with sed

How can I use sed or any utility to remove any word that begins with TRS-, I have tried sed 's/ERA.*//g' but seems not to be working Input: 23 TRS-458-9 345 235 45 TRS-42-5 423 000 76 300 234 Output: 23 345 235 45 423 000 76 300 234 (5 Replies)
Discussion started by: aydj
5 Replies

5. Shell Programming and Scripting

Remove last word of a string?

Hello I have a string that may or may not have 4 dots. The string is actualy a file within a folder, where multiple files are located. Files may look like: # ls * creds: 192.168.10.110 someserver shares: 192.168.10.110.Public someserver.sharefolder # I want to fill 2 variables,... (1 Reply)
Discussion started by: sea
1 Replies

6. Shell Programming and Scripting

Remove 1st word and _ from string

var=abc_cde_def_ghi_678.txt Expected output: cde_def_ghi_678.txt Is there a better way to achive this other than cut command? Basically, I need to remove the 1st word and _ from the string. Thanks. (1 Reply)
Discussion started by: vedanta
1 Replies

7. Shell Programming and Scripting

want to remove last word.

Hi, I have a file which has the following /u12/data/oracle/abc.dbf /u12/data/oracle/def.dbf /u12/data/oracle/daf.dbf /u12/data/oracledb/fgh.dbf /u12/data/oracledb/fkh.dbf /u12/data/oracledb/kdq.dbf I want to do something like this /u12/data/oracle /u12/data/oracle... (7 Replies)
Discussion started by: javeedkaleem
7 Replies

8. Shell Programming and Scripting

Remove particular word from file

Hi All, If my file is: Wed Sep 9 22:45:14 EDT 2009 sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> This is log file generated from transfer... sftp> sftp> sftp> sftp> Files placed properly.... sftp> sftp> sftp> How can I remove "sftp>" word from this... (4 Replies)
Discussion started by: darshakraut
4 Replies

9. UNIX for Dummies Questions & Answers

using grep and to remove all word with uppercase

I try to write a small script that looks in the file tt for all the words that start with m in lowercase and in which there is no uppercase. #!/bin/sh grep ^m\.*\.\.* tt (4 Replies)
Discussion started by: cfg
4 Replies

10. Shell Programming and Scripting

how to remove first word

Hi, i have a question about to remove first word from a sentence. my script; #!/usr/bin/perl $msgtxt = "this is a test script"; my @ap_txtMsg = split(/ +/, trim_data($msgtxt)); $ap_msgtxt = splice (@ap_txtMsg, 0, 1); print $ap_msgtxt; but the output is first word that i... (1 Reply)
Discussion started by: malaysoul
1 Replies
Login or Register to Ask a Question