echo and grep commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo and grep commands
# 1  
Old 02-10-2012
Question echo and grep commands

Hey im new in this...anything will be helpful...

The user will input the word or phrase .... I want to search the user input in file (by lines) but not all then with this line search on another file ( with the specific line) and show to the user.

Example:

file1.txt
=======
a
aa
aaa
aab
aac


file2.txt (corresponding md5 hashes of every text line)
======
0cc175b9c0f1b6a831c399e269772661
4124bc0a9335c27f086f24ba207a4912
47bce5c74f589f4867dbd57e9ca9f808
e62595ee98b585153dac87ce1ab69c3c
a9ced3dad556814ed46042de696e1849

========
Lets supposed to the user enter (want to crack) this hash: a9ced3dad556814ed46042de696e1849

im using
Code:
grep -n -w a9ced3dad556814ed46042de696e1849 file2.txt

but i want the output --> aac

Any ideas Smilie??


Thanks in advance
# 2  
Old 02-10-2012
Try this..
Code:
#!/bin/bash
linenum=$( grep -w -n a9ced3dad556814ed46042de696e1849 file2.txt | cut -f1 -d: )
sed -n "$linenum p" file1.txt

--ahamed
# 3  
Old 02-10-2012
Quote:
Originally Posted by ahamed101
Try this..
Code:
#!/bin/bash
linenum=$( grep -w -n a9ced3dad556814ed46042de696e1849 file2.txt | cut -f1 -d: )
sed -n "$linenum p" file1.txt

--ahamed
YES. It Works!

But Im trying to call this command (sed -n "$linenum p" file1.txt) from a pipeline in C and I doesn't works ... And I think the error is the double quotes can i run the command something different.. sed -n $linenum p file1.txt (but this way doesn't work)

look my var

Code:
char sed[1024] = "sed -n "$linenum" p file.txt;

Thankss in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Behaviour of echo commands used by Linux admins

version info : Fedora 28 (Kernel version: 4.16.12-300) shell : bash Using echo command , if I redirect a text like "Chocolate" to a file , all the contents in the file are overwritten as shown below. # cat /tmp/someTest Hello world One more Hello world myLine3 # echo... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Red Hat

Echo and grep issues

Is there an environment issue that would not allow the following not store and pass the value into this field: underScorePresent=`echo $USER | grep "_" | wc -l` It is running on a new redhat 6.5 OS. The value $USER is set to cpac. It is a vendor code and they are saying it is environment... (1 Reply)
Discussion started by: mrn6430
1 Replies

3. Shell Programming and Scripting

Using echo, grep and wc and outputing to text file

My current line command is as follows: echo -n "text: " ; grep "blah text" ../dir1/filename | wc -l The output to the screen is as needed, but how do I print to a text file? (9 Replies)
Discussion started by: ncwxpanther
9 Replies

4. UNIX for Dummies Questions & Answers

Echo out running commands

Is there any way in a script to print out the commands being ran? In DOS script, there is the "@echo on" and "@echo off". so I have a script like this: #!/bin/ksh echo "hello there. moving files." <turn on echoing here> cp thisfile.txt thatfile.txt cp whatfile.prop whyfile.prop <turn... (2 Replies)
Discussion started by: ronron5477
2 Replies

5. UNIX for Dummies Questions & Answers

Having a hard time with the sed/echo commands?

Hello, well what I'm trying to do is to remove underscores from filenames and leaving empty spaces instead: arturas@Universe:/windows/Center/training$ ls big_file failas su shudu arturas@Universe:/windows/Center/training$ a=big_file arturas@Universe:/windows/Center/training$ mv $a `echo... (8 Replies)
Discussion started by: arcelivez
8 Replies

6. Shell Programming and Scripting

Advice using cut & echo combination commands

Hi, I am cutting data from a fixed length test file and then writing out a new record using the echo command, the problem I have is how to stop multiple spaces from being written to the output file as a single space. Example: cat filea | while read line do field1=`echo $line | cut -c1-2` ... (6 Replies)
Discussion started by: dc18
6 Replies

7. Shell Programming and Scripting

SSH, Remote Commands and echo, oh my!

So, HostB has a SSH trust via pre-shared keys from HostA. HostA> ssh HostB hostname HostB HostA> ssh HostB echo `hostname` HostA HostA> ssh HostB 'echo `hostname`' `hostname` HostA> ssh HostB "echo `hostname`" HostA HostA> ssh HostB echo $PS1 user@HostA:$PWD HostA> ssh HostB... (12 Replies)
Discussion started by: Wrathe
12 Replies

8. Shell Programming and Scripting

help with grep and echo

Can't get this to work. Something is wrong with the systax maybe. :o if ] && ] ; then: Thanks (2 Replies)
Discussion started by: rstone
2 Replies

9. UNIX for Dummies Questions & Answers

How do I output or echo NONE if grep does not find anything?

I am performing a grep command and I need to know how to echo "NONE" or "0" to my file if grep does not find what i am looking for. echo What i found >> My_File grep "SOMETHING" >> My_File I am sure this is easy, I am sort of new at this! Thanks (2 Replies)
Discussion started by: jojojmac5
2 Replies

10. Shell Programming and Scripting

small question of echo | grep command

Hi, i've got the following: a=`echo $b | grep '^.*/'` i'm storing in the variable the value of the variable b only if it has a / somewhere. It works, but i don't want to print the value. How do i give the value of b to the grep command without the echo? thanks! (5 Replies)
Discussion started by: kfad
5 Replies
Login or Register to Ask a Question