Question about partial searching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about partial searching
# 8  
Old 10-15-2010
I did paste that in a dummy script and renamed it accordingly but it didnt output anything.

The script did run to the user input stage and then concluded. I am trying to understand your code as well Smilie I get everything except that I cant seem to find where the grep search would go into the file 'playlist' to hunt down the user input.


Let me know if you'd like me to clarify anything, sometimes I can be vague. Smilie thank you for your time


I can try explaining again. So user inputs a name(can be full or partial). The script has to check whether the name exists in the database file(playerlist). Once the script finds a match, it should output the first name and last name columns (12-26, 44-58), however it should check every single line for duplicate first names. So if Michael appears twice, there should be two lines with both Michaels as outputs. I figured a while loop would be appropriate. I will try to play with the code you gave in the meantime though Smilie

---------- Post updated at 03:21 PM ---------- Previous update was at 03:05 PM ----------

here's what I was thinking for the while loop

Code:
rowCount=$(wc -l <playerlist) #this would store the number of lines in the db

while [ $rowCount - ne 0 ]
do 
  some grep function to search line @ rowCount and output if match found
  rowCount=$(($rowCount-1))
done

# Im thinking that should output all matches found within the database file


Last edited by Scott; 10-16-2010 at 07:43 AM.. Reason: Code tags
# 9  
Old 10-15-2010
You could make the list of patterns into a sed script to go through once and print out what matches any, and even with the first it matches:

Code:
 
sed '
  /pattern1/b
  /pattern2/b
  .
  .
  .
  /patternN/b
  d
 '

or:
Code:
 
sed '
  s/.*pattern1/pattern1: &/
  t
  s/.*pattern2/pattern2: &/
  t
  .
  .
  .
  s/.*patternN/patternN: &/
  t
  d
 '

# 10  
Old 10-15-2010
Quote:
Originally Posted by Sagramor
I can try explaining again. So user inputs a name(can be full or partial). The script has to check whether the name exists in the database file(playerlist). Once the script finds a match, it should output the first name and last name columns (12-26, 44-58), however it should check every single line for duplicate first names. So if Michael appears twice, there should be two lines with both Michaels as outputs. I figured a while loop would be appropriate. I will try to play with the code you gave in the meantime though
Code:
rowCount=$(wc -l <playerlist) #this would store the number of lines in the db
while [ $rowCount - ne 0 ]
do 
    some grep function to search line @ rowCount and output if match found
    rowCount=$(($rowCount-1))
done

No need to count the lines:
Code:
while read L
do
   echo "$L"
done <playerlist

Above code reads each line of playerlist and assigns it to the variable L; then prints the variable on screen, until nothing can be read (EOF is reached).
Running the above code should perform the same as typing cat playerlist

Name1=${L:11:14} extracts 14 chars from the 12th char of $L
This User Gave Thanks to frans For This Post:
# 11  
Old 10-15-2010
ahh okay I understand now!

I ran the script and got this
Code:
./test: line 5: conditional binary operator expected
./test: line 5: syntax error near `=~"Name1"'
./test: line 5: `      [[ "$S" =~"Name1" ]] && echo "Name: $Name1 ${L:43:15}"'


Last edited by Scott; 10-16-2010 at 07:43 AM.. Reason: Code tags
# 12  
Old 10-15-2010
=~ is a BASH-ism and won't work in other shells. Even in BASH, I don't think it works the way you have it. What are you trying to do?
# 13  
Old 10-15-2010
that particular part is supposed to check if the user input equals or partially equals $Name1
# 14  
Old 10-15-2010
"partially" equals? What does that mean?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Partial Match and Replace

Hi, I have a tab delimited text file like this one. I need to do a partial match of a particular cell and then replace matches with an empty cell. So here is a sample: Smith FordMustang ChevroletCamaro Miller FordFiesta Jones KiaSorrento Davis ChevroletCamaro Johnson ToyotaHighlander I... (4 Replies)
Discussion started by: mikey11415
4 Replies

2. UNIX for Dummies Questions & Answers

How to substitute for the partial match?

Hi I have a question and hope I can get answer here. Thank you in advance. I have two files: file1: aa X bb Y cc Z file2: cc A bb B dd C aa D bb E If the 1st column match in both file1 and file2, the 2nd column in file2 will be replaced by the 2nd column in file1. If there is no... (2 Replies)
Discussion started by: yuejian
2 Replies

3. Shell Programming and Scripting

URL partial matching

I have two files: file 1 http://www.hello.com http://neo.com/peace/development.html, www.japan.com, http://example.com/abc/abc.html http://news.net http://lolz.com/country/list.html,www.telecom.net, www.highlands.net, www.software.com http://example2.com ... (1 Reply)
Discussion started by: csim_mohan
1 Replies

4. Shell Programming and Scripting

Partial retrieve

I have this in log file /var/log/maillog XXX YYY ZZZ :15214 I=:25 AAA BBB CCC I need awk/sed operation on this, so that it retrieves only the first IP. cat /var/log/maillog | sed_operation 55.66.77.88 (2 Replies)
Discussion started by: anil510
2 Replies

5. Shell Programming and Scripting

How to replace partial string

I have a list of strings in file: 10 10 AAA 120 13 BBBBB 23 11 CCCCC 11 32 DDDDDD I want to replace first column of the text such as: 10, 129, 23, 11 with 11, 22, 33, 44. I can do line by line, but just not sure how to replace partial string without... (1 Reply)
Discussion started by: ford99
1 Replies

6. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

7. Shell Programming and Scripting

Partial Delete Lines

Hi, Need to delete line prior to (INSERT/UPDATE/DELETE). In case ' available, then keep that. Pls refet below details. Input ====================== l_s := ' INSERT INTO TEST' l_P PD := ' UPDATE INTO TEST' l_D := ' DELETE INTO TEST' This is test Output... (4 Replies)
Discussion started by: saurabhbaisakhi
4 Replies

8. Shell Programming and Scripting

get partial numbers from a string

Hi Everyone, I have: $val="QQ3_1899_CD4". The output will be: 1899. I did $val =~ /(\d+)/g; the output is 318994, then i use substr to get those 1899. This is not efficient. Is any simple way, like just one line can do? Thanks (1 Reply)
Discussion started by: jimmy_y
1 Replies

9. UNIX for Dummies Questions & Answers

Searching partial columns and returning maximum as output

Hello, I am just getting starting with awk and wondering if anyone could help with the following problem. I have a large file of data, 50,000 rows x 6 columns. I would like to search in blocks of 500 rows for a maximum value in a specific column and compile an output file that prints the... (0 Replies)
Discussion started by: xb_analysis
0 Replies

10. UNIX for Dummies Questions & Answers

searching text question

If I am searching through a text file, and it is setup in hierarchical fashion. ie: Memory: 256 MB DDR Kingston CPU: UltraSparc 800 Mhz can i somehow search for CPU and pull out lines below it as well? Like grep only pulls that one line, i want that line... (4 Replies)
Discussion started by: BG_JrAdmin
4 Replies
Login or Register to Ask a Question