matching pattern to end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting matching pattern to end of line
# 1  
Old 07-25-2012
matching pattern to end of line

I have the following code and want to get only the comments.

Ideally I would like to replace the characters to the left of the first '!' in the line with blanks.

Code:
 
  real, dimension(:), allocatable :: ft  ! stores a single trace
  real, dimension(:), allocatable :: tr  ! stores a single trace (extended to size of ft)
                                                            
  nt = size(tcube,1)
  nx = size(tcube,2)
  ny = size(tcube,3)
  nf = size(fcube,1)

  ! trace in the frequency domain
  allocate( ft(nf) )

  ! trace extended to size(ft)
  allocate( tr(nf) )

Output would be as follows.

Code:
 
                                         ! stores a single trace
                                         ! stores a single trace (extended to size of ft)
  ! trace in the frequency domain
  ! trace extended to size(ft)


Last edited by kristinu; 07-25-2012 at 07:08 AM..
# 2  
Old 07-25-2012
Before we start finding you a solution, would you mind providing a sample of the desired output file?
# 3  
Old 07-25-2012
Hi

Code:
grep '!' infile | sed 's/.*!/!/'

# 4  
Old 07-25-2012
Quote:
Originally Posted by Chirel
Hi

Code:
grep '!' infile | sed 's/.*!/!/'

Tried
Code:
  grep "!" radon3d_subs.f90 | sed 's/.*!//'

but am getting
Code:
//: Event not found.

# 5  
Old 07-25-2012
Code:
awk '/!/{gsub(/./," ",$1); print }' OFS=! FS=! infile

# 6  
Old 07-25-2012
Got an error using the following

Code:
grep '!' radon3d_subs.f90 | sed 's/.*!/!/'
/!/: Event not found.

---------- Post updated at 05:34 AM ---------- Previous update was at 05:32 AM ----------

Quote:
Originally Posted by ripat
Code:
awk '/!/{gsub(/./," ",$1); print }' OFS=! FS=! infile

The command gives an error

Code:
awk '/{gsub(/./," ",$1); print }' OFS=! FS=! radon3d_subs.f90
awk: fatal: Unmatched ( or \(: /{gsub(/

---------- Post updated at 05:39 AM ---------- Previous update was at 05:34 AM ----------

Seems that the 'Event not found' error is from the csh shell. Unfortunately on this machine I have to use csh, so I escape the !.
# 7  
Old 07-25-2012
Quote:
Originally Posted by kristinu
Code:
awk '/{gsub(/./," ",$1); print }' OFS=! FS=! radon3d_subs.f90
awk: fatal: Unmatched ( or \(: /{gsub(/

Is not what I have posted. You must filter the output with /!/
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetching a line matching a pattern

Hi Gurus, I have a file as follows (Sample shown below but the list is very huge) SCHEDULE WS1#JS1 RUNCYCLE1 : WS1#JOB1 WS1#JOB2 FOLLOWS JOB1 END SCHEDULE WS2#JS1 RUNCYCLE2 : WS1#JOB3 WS1#JOB1 FOLLOWS JOB3 WS2#JOB1 (10 Replies)
Discussion started by: jayadanabalan
10 Replies

2. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

3. Shell Programming and Scripting

Matching pattern in two files and print the line

Hi, I want to match the pattern in file1 with file2 and print the value in file2 and paste in file1 file1: ISHO RT SR Major 96.46778 Drop Call Rate CS Critical 0.5072662 ISHO RT SR Major 97.754364... (3 Replies)
Discussion started by: khalil
3 Replies

4. Shell Programming and Scripting

Need correct pattern at end of line

I have some data as below. I need correct it as result. Data: BG1:100+10++II DG1:200+100+1234 DG2:300+200++II CG1:200+100+1111 DG2:400+100++II DG6:200+200+2345 DG2:400+100+2222 Result: BG1:100+10++II DG1:200+100+1234 DG2:300+200++1 CG1:200+100+1111 DG2:400+100++1... (4 Replies)
Discussion started by: mr.awk
4 Replies

5. UNIX Desktop Questions & Answers

matching 3 digits at the begining and the end of the line

I have a file with hundreds of records and I need to find those records that have three digits at the beginning and the same three digits at the end. $GREP '\(\)\(\)\(\)\3\2\1'I believe this is part of the script but I am not sure how to compare these 3 digits with the 3 digits at the end of... (2 Replies)
Discussion started by: bartsimpsong
2 Replies

6. Shell Programming and Scripting

Extracting a string matching a pattern from a line

Hi All, I am pretty new to pattern matching and extraction using shell scripting. Could anyone please help me in extracting the word matching a pattern from a line in bash. Input Sample (can vary between any of the 3 samples below): 1) Adaptec SCSI RAID 5445 2) Adaptec SCSI 5445S RAID 3)... (8 Replies)
Discussion started by: jharish
8 Replies

7. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

8. Shell Programming and Scripting

how to append the pattern at the end of the line

-Hi I have multiple files which contain a line with the word "exec". I need to add the following pattern " -cmode -ccheap" on the same line where "exec" is at the end. Any idea? Thanks a lot in advance to everybody... -A (2 Replies)
Discussion started by: aoussenko
2 Replies

9. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies

10. Shell Programming and Scripting

extract a particular start and end pattern from a line

hi In the foll example the whole text in a single line.... i want to extract text from IPTel to RTCPBase.h. want to use this acrooss the whole file Updated: IPTel\platform\core\include\RTCPBase.h \main\MWS2051_Sablime_Int\1... (7 Replies)
Discussion started by: manish205
7 Replies
Login or Register to Ask a Question