Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I need to write one c-shell command that does the following:
using the unix "find" command , i need to find all the files, from the current directory and downwards, whose name end with .txt and that contain the string "some text", and for each file that is found, print the first 4 letters of its name.
again, this is supposed to be done in one c-shell command.
2. Relevant commands, code, scripts, algorithms:
i am asked to use the "find" command
3. The attempts at a solution (include all code and scripts):
i managed to write a command that finds all the files whose name ends with .txt and that contain the string "some text", and for each file that is found, prints its name.
with this command:
find -name *.txt -exec grep -h "some text" {} \;
but i couldn't find a way to only print the first 4 letters of each file name.
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
i am a student in Tel-Hai college in northern Israel.
the professor is Guy Leshem.
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
To get the filename I think you should be using "grep -l" not "grep -h".
Enclose the wildcard filename in single quotes to cause "find" to expand the filenames not Shell.
Confine the search to files "-type f".
I dont' write "csh" code, but you will need to process each filename with the "basename" command to remove the directory tree information from each filename, then use "cut" to shorten each filename.
You may have completed your assignment, but this is worth knowing: the xargs command comes in very handy here:
The -l option of grep prints only the filename of matching files. The sed command is another way of achieving the effect used by "cut", above.
The reason for xargs is efficiency: instead of calling "grep" for each file, as find does, xargs calls grep only as many times as needed given the OS constraints (length of command line). In everyday work, I use it once a day at least.
Hi everyone
I have a problem with my script
If I try directly this command
/usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz
It works
But if I simply add this command in a script and... (8 Replies)
Can someone point me to the right command to to run another shell on top of your default shell?
Thanks
PS If admin sees this It is not home work. I am old man who wants to learn unix in my spare time. I CURRENTLY DO NOT GO SCHOOL, COLLEGE OR UNIVERSITY. (2 Replies)
I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found"
My code is as follows:
--------------------------
#!/bin/sh
user="test"
DIR="/bldtmp/"$user
VIEW="test.view1"
echo "TMPDIR before export... (4 Replies)
basically i'm tired of hitting the left arrow a few dozen times when correcting a mistake or modifying a history command
i'd like to use vim style key shortcuts while on the command line so that a 55 moves the cursor 55 places to the left...
and i want all the other vi goodies, search of... (3 Replies)
Hello.
I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct.
We have a script (ftp.script) which calls on... (1 Reply)
i want to search in the current directory all the files that contain one word for example "hello"
i want to achieve it with the grep command but not with the grep * (2 Replies)
I'm trying to read a bunch of log files and output the lines that contain particular strings.
To accomplish this, I've been running the following from the command line:
find . -name "*" | xargs grep " " | grep " " > output.txt
Two grep statements are needed in case I'm looking for a... (3 Replies)
Hello,
I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is
sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name3>' |... (1 Reply)
Hello,
I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is
sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name3>' |... (0 Replies)