Search for the information at file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Search for the information at file
Prev   Next
# 1  
Old 09-13-2018
Search for the information at file

I'm having few question.

i'm have a input file.

Code:
Other information
CONNECTIONS
  "BP-COLLECTOR"
    J6.4
    "BP-TEST".4;
  +5VS
    C34.1
     U21.1;
  DEV_I2C_SDA
    J6.6
    R4.1
    U18.1;
DEVICES
  "BP-TEST"
    1."BP-LED_ANODE"
    2."BP-LED_CATHODE"
    3."BP-VCC"
    4."BP-COLLECTOR"
    5."BP-EMITTER";
  D1
    1."-5V"
    2.N15483385;
END

fileB
Code:
BP-COLLECTOR
DEV_I2C_SDA


will get the information below BP-COLLECTOR until meet ; , but without " and ; symbol at final output.
expected output file:
Code:
J6.A1
BP-TEST.4
J6.6
R4.1
U18.1




below is the code i'm try search from internet and able to use, but only work on 1 variable, but i might having 100 + variable from 1 file.
Code:
rm -f n2p.temp1
rm -f n2p.temp2
rm -f n2p.temp3
rm -f n2p.temp4
rm -f n2p.temp5
rm -f n2p.temp6

perl -lne "print if/CONNECTIONS$/../DEVICES/" board > n2p.temp1  
sed 's/\"//g' n2p.temp1 > n2p.temp2


perl -lne "print if/BP-COLLECTOR$/../;/" n2p.temp2 >n2p.temp3
sed 's/\;//g' n2p.temp3 > n2p.temp4
sed 's/\ //g' n2p.temp4 > n2p.temp5

sed 1d n2p.temp5 > n2p.temp6

rm -f n2p.temp1
rm -f n2p.temp2
rm -f n2p.temp3
rm -f n2p.temp4
rm -f n2p.temp5

another question is, i'm always use one line perl scrip to solve some of my problem.
example :
Code:
perl -lne "print if/BP-COLLECTOR$/../;/" n2p.temp2 >n2p.temp3

is that possible , make the BP-COLLECTOR as a variable that from 1 file ? so i no need do multiple line for all variable to done 1 job.




Moderator's Comments:
Mod Comment Please use CODE tags consistently as required by forum rules!

Last edited by RudiC; 09-13-2018 at 06:29 AM.. Reason: Added some CODE tags.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

2. UNIX for Dummies Questions & Answers

Search file and print everything except multiple search terms

I'm trying to find a way to search a range of similar words in a file. I tried using sed but can't get it right:sed 's/\(ca01\)*//'It only removes "ca01" but leaves the rest of the word. I still want the rest of the information on the lines just not these specific words listed below. Any... (3 Replies)
Discussion started by: seekryts15
3 Replies

3. Shell Programming and Scripting

Retrieving the relevant search from search file in the main file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search... (7 Replies)
Discussion started by: csim_mohan
7 Replies

4. UNIX for Dummies Questions & Answers

Obtaining File information based on String Search

Is there a single Command in Unix to get the following Information when searching for files containing one or more strings in a Unix Directory (including sub directories within it) : 1) Complete filename ( path and filename) 2) Owner of the file 3) Size of the file 4) Last Modified date... (3 Replies)
Discussion started by: pchegoor
3 Replies

5. UNIX for Dummies Questions & Answers

Grep? - using a file of terms to search another file when the information is on a different line

I have a flat file that looks like this, let's call it Chromosome_9.txt: FT /Gene_Name="Guanyl-Acetylase 9" FT /Gene_Number"36952" FT /Gene_Name="Endoplasmic Luciferase" FT /Gene_Number"36953" FT ... (4 Replies)
Discussion started by: Twinklefingers
4 Replies

6. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

7. Shell Programming and Scripting

search information in multiple files and save in new files

hi everyone, im stuck in here with shell :) can you help me?? i have a directory with alot files (genbank files ... all ended in .gbk ) more than 1000 for sure ... and i want to read each one of them and search for some information and if i found the right one i save in new file with new... (6 Replies)
Discussion started by: andreia
6 Replies

8. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

9. Shell Programming and Scripting

sed help - search/copy from one file and search/paste to another

I am a newbie and would like some help with the following - Trying to search fileA for a string similar to - AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3 I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

10. Shell Programming and Scripting

sed search and read the RHS information: Linux 2.6.9-89

Hi, I have a config_file.cfg with the content: FILE_ID_1=1 FILE_FTP_ID_1=<FTP_SERVER1.COM> .... FILE_ID_2=2 FILE_FTP_ID_2=<FTP_SERVER2.COM> .... so on for 28 times. As you might have guessed it; the script I have to write is to read this config file and get the FTP server... (3 Replies)
Discussion started by: dips_ag
3 Replies
Login or Register to Ask a Question