Filter line in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter line in a script
# 1  
Old 06-21-2016
Filter line in a script

Hi Team,

I am trying hard to find a way I can filter a line as below:

If I have a line as

Code:
/abc /def 123:/ghi /jkl 456:/mno /pqrs 7890:/tuvw /xyz


I am expecting my output to be as below:

Code:
/abc /def /jkl /pqrs /xyz

basically I want to ignore anything preceding or succeeding colon (":") from a line.

Please help.


Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 06-22-2016 at 03:38 AM.. Reason: code tags
# 2  
Old 06-21-2016
Quote:
Originally Posted by SiddhVi
Hi Team,

I am trying hard to find a way I can filter a line as below:

If I have a line as

/abc /def 123:/ghi /jkl 456:/mno /pqrs 7890:/tuvw /xyz


I am expecting my output to be as below:

/abc /def /jkl /pqrs /xyz

basically I want to ignore anything preceding or succeeding colon (":") from a line.

Please help.
Please, try:
perl -pe 's/\s\d+:\/\w+//g' SiddhVi.file
# 3  
Old 06-22-2016
sed approach:
Code:
sed 's/\(^\| \)[^ ]*:[^ ]*\( \|$\)/ /g' file
/abc /def /jkl /pqrs /xyz

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need output in one line and filter servers, which has account expired or password exipred

I have 500 servers, in which I am looking to get hostname and password length information. when I am trying to run script(which I build), in which shows output in one line below and asking to reset password and also some of the servers does not give output. Please help #!/bin/bash for... (9 Replies)
Discussion started by: yash_message
9 Replies

2. Shell Programming and Scripting

awk or sed or grep filter a line and/or between strings

Hi, I have multiple files on a directory with the following content: blahblah blahblah hostname server1 blahblah blahblah ---BEGIN--- aaa bbb ccc ddd ---END--- blahblah blahblah blahblah I would like to filter all the files with awk or sed or something else so I can get below... (6 Replies)
Discussion started by: bayupw
6 Replies

3. Shell Programming and Scripting

awk Help: Filter Multiple Entry & print in one line.

AWK Gurus, data: srvhcm01 AZSCI srvhcm01 AZSDB srvhcm01 BZSDB srvhcm01 E2QDI31 srvhcm01 YPDCI srvhcm01 YPDDB srvhcm01 UV2FSCR srvhcm01 UV2FSBI srvhcm01 UV2FSXI srvhcm01 UV2FSUC srvhcm01 UV2FSEP srvhcm01 UV2FSRE srvhcm01 NASCI srvhcm01 NASDB srvhcm01 UV2FSSL srvhcm01 UV2FSDI (7 Replies)
Discussion started by: rveri
7 Replies

4. UNIX for Dummies Questions & Answers

Command line / script option to filter a data set by values of one column

Hi all! I have a data set in this tab separated format : Label, Value1, Value2 An instance is "data.txt" : 0 1 1 -1 2 3 0 2 2 I would like to parse this data set and generate two files, one that has only data with the label 0 and the other with label -1, so my outputs should be, for... (1 Reply)
Discussion started by: gnat01
1 Replies

5. Shell Programming and Scripting

Filter files by exact line anywhere in file

I have two files. L1 and L2. (each file, has one string per line without any spaces) I would like to get those lines in L1 that are not present anywhere in L2. No substring match, just exact line by line match but it can be anywhere in the file. (line 5 in L1 may be present in line 22 of L2,... (2 Replies)
Discussion started by: nick2011
2 Replies

6. Shell Programming and Scripting

[ask]filter with line number in file

dear all about my last question in fileA.txt (all list line i want to find in fileB.txt) is content of line number fileA.txt 23 34 35 55 59 and fileB.txt is content like 24:asd|ekkk|001|001 123:bca|egsd|210|002 1231:cas|egds|322|231 ... in fileB.txt they have line number like... (5 Replies)
Discussion started by: zvtral
5 Replies

7. Shell Programming and Scripting

filter out a sequence from multiple lines line

Hi, I have an unwanted string at random lines of my verilog (*.v) file. (* abccddee *) input A; (* xyz *) input B; (* 1234 *) output C; I want a clean file like this: input A; input B; output C; the unwanted string begins with "(*" and ends with "*)" at multiple lines. Any help... (2 Replies)
Discussion started by: return_user
2 Replies

8. Shell Programming and Scripting

How to filter a whole line using a word?

Hello Team, I have a script in which more than 500 trigger statemetns are written. i need to filter all lines from that script file which containts "CREATE TRIGGER" word in each line is it possible using linux commands?? example: CREATE TRIGGER S1.T1 .................. (10 Replies)
Discussion started by: kanakaraju
10 Replies

9. Shell Programming and Scripting

How to filter only comments while reading a file including line break characters.

How do I filter only comments and still keep Line breaks at the end of the line!? This is one of the common tasks we all do,, How can we do this in a right way..!? I try to ignore empty lines and commented lines using following approach. test.sh # \040 --> SPACE character octal... (17 Replies)
Discussion started by: kchinnam
17 Replies

10. UNIX for Dummies Questions & Answers

how do I filter for a specific line in a file?

It seems like it should be very simple to have a command like grep return a specific line from a file but I can't find anything in the man pages to make grep search by line. I've looked in cat as well. Anyone know how to return a single line from a file? (5 Replies)
Discussion started by: gelitini
5 Replies
Login or Register to Ask a Question