Finding Strings between 2 characters in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding Strings between 2 characters in a file
# 8  
Old 03-10-2013
One way might be:
Code:
awk '{$1=$1; sub($1 FS $2 FS,x)}1' RS= file

But only if the empty lines are completely empty (contain no whitespace).

Last edited by Scrutinizer; 03-10-2013 at 07:30 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 9  
Old 03-10-2013
Thanks for the reply. I am not sure if empty lines will be completely empty, can we do one thing if that does not need any kind of assumption...I am fine closing the data in the end with ";", so is there anyway we can get the string which starts with "=" and ends with ";".
Your solution again getting me the all lines of file in one go...requesting to please let me know if i can get one by one as explained in the post. Once again thanks for spending time on this on helping me.

---------- Post updated at 06:01 AM ---------- Previous update was at 05:34 AM ----------

Also please note that it is not a fixed length file that means the number of words are not fixed...
# 10  
Old 03-10-2013
One thing that is not clear is, where does the script get the information that "C" files need an extension ".c" and C++ files need ".cpp" etc..
# 11  
Old 03-10-2013
that information will not come from anywhere...once i am able to extract the strings...then i need to write function which will check for validation...but in 1st place i dont know how to extract the string...I hope I am clear...do we have any instr oracle like command in Unix..if something like that is there...then i can simple get the position of ";" and then from there i can get substring using substr...Any advice please..
# 12  
Old 03-10-2013
Perhaps something like this is more what you are looking for:
Code:
#!/bin/bash
while read -a line
do
  if [[ ${line[1]} == "=" ]]; then
    ptype=${line[0]}
    unset line[0] line[1]
  fi
  for file in "${line[@]}"
  do
    echo "Check if \"$file\" belongs to type \"$ptype\""
  done
done < infile

This User Gave Thanks to Scrutinizer For This Post:
# 13  
Old 03-10-2013
Thank You...This is what i was looking for. If possible could you please confirm the following points:line[1] does it mean, "=" operator in my file has to be 2nd word in each line without any space.
# 14  
Old 03-10-2013
Yes, that is correct.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding distinct characters from flat file

Hi....I need one help.... I'm having a files which is having the data as follows... a b c c d d d e f Now I need to find out distinct characters from this file and the output should be as follows - a b c d e f Can you please help me on this? I'm using KSH script. (18 Replies)
Discussion started by: Krishanu Saha
18 Replies

2. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

3. Shell Programming and Scripting

Finding/replacing strings in some files based on a file

Hi, We have a file (e.g. a .csv file, but could be any other format), with 2 columns: the old value and the new value. We need to modify all the files within the current directory (including subdirectories), so find and replace the contents found in the first column within the file, with the... (9 Replies)
Discussion started by: Talkabout
9 Replies

4. UNIX for Dummies Questions & Answers

Finding specific series of strings or characters

After spending sometime playing around with my script I just cannot get it to do what I want. So I decided to ask. My file looks something like this: I am using the following code to extract sequences that contain dashes awk '/^>/{id=$0;next}{if (match($1,"-")) print id "\n" $0}' infile ... (17 Replies)
Discussion started by: Xterra
17 Replies

5. Shell Programming and Scripting

Finding File Names Ending In 3 Random Numerical Characters

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190 each of this files is in a directory named for the file but excluding the extension. Now the last three numeric characters, in this case 999, can be anything from 001 to 999, I need to... (3 Replies)
Discussion started by: roche.j.mike
3 Replies

6. Shell Programming and Scripting

Finding number of strings in List

I have a list of strings stored in $Lst Example set Lst = "John Fred Kate Paul" I want to return 4 in this case. (1 Reply)
Discussion started by: kristinu
1 Replies

7. UNIX for Dummies Questions & Answers

Help with finding matching position on strings

I have a DNA file like below and I am able to write a short program which finds/not an input motif, but I dont understand how I can include in the code to report which position the motif was found. Example I want to find the first or all "GAT" motifs and want the program to report which position... (12 Replies)
Discussion started by: pawannoel
12 Replies

8. Shell Programming and Scripting

mappin strings of two different file and finding the mapped string and then map other fields.

As i am new to unix so facing some problems in scripting: here is my question: i m having two files. 1st file say a.txt contain 3 column like SPECIALITY|UMP_CODE|SPECIALTY_CODE Addictive Diseases|25ADD|ADD Addictive Diseases/Family Practice|25ADD|ADD/FP Aerospace Medicine|1.041666667|AM... (4 Replies)
Discussion started by: dsh007
4 Replies

9. Shell Programming and Scripting

Finding strings

Hi I made a post earlier but now my problem has become a lot more complicated. So I have a file that looks like this: Name 1 13 94 1 AGGTT Name 1 31 44 1 TTCCG Name 1 13 94 2 AAAAATTTT Name 1 41 47 2 GGGGGGGGGGG So the file is tab delimited and what I want to do is find... (8 Replies)
Discussion started by: kylle345
8 Replies

10. Shell Programming and Scripting

Read file and remove special characters or strings

Hello all I am getting data like col1 | col2 | col3 asdafa | asdfasfa | asf*&^sgê 345./ |sdfasd23425^%^&^ | sdfsa23 êsfsfd | sf(* | sdfsasf My requirement is like I have to to read the file and remove all special characters and hex characters ranging form 00-1f from 1st column, remove %"'... (1 Reply)
Discussion started by: vasuarjula
1 Replies
Login or Register to Ask a Question