------------------------------------------------
------------------------------------------------
now, test.txt is hardcoded.....i want to check how can my code consider the file which the user specifies.... in short i want to read the file which will be inputted by the user.
please help
Last edited by Franklin52; 03-26-2012 at 03:27 AM..
Reason: Please use code tags for code and data samples, thank you
------------------------------------------------
#!/bin/sh
cat test.txt| sed '1d' | sed '$d' > /tmp/tmp1.txt
while read line
do
typeset -i count=`echo $line | tr ' ' '}' | wc -c`
finalcount=`expr $count - 1`
echo $finalcount
done < /tmp/tmp1.txt
------------------------------------------------
now, test.txt is hardcoded.....i want to check how can my code consider the file which the user specifies.... in short i want to read the file which will be inputted by the user.
please help
You can do it in two ways,
1. command line option
2. read command
First Method:
Consider this script name is 1.sh. you have to call this script, 1.sh test.txt Second Method:
Consider this script name is 1.sh. you have to call this script, 1.sh
In second method, the script waits until you give input manually,
---------- Post updated at 01:11 AM ---------- Previous update was at 01:04 AM ----------
Now, with the same file, if I want to store the values of variable 'finalcount' in a file or a log file, along with the line numbers...how do i achieve it?
thnx in advance
script.sh:
This way you can instead do:
A big warning, though: be careful what you feed this baby, because read -r and echo -E may still modify your input by parsing it!
BTW, I noticed you replaced all whitespace with curly braces but wc -c also counts the whitespaces, I mean, if that was your reason for using tr. And also, I think you may remove typeset -i without altering the functionality of your script, if all you want to do is count the amount of characters per line.
The thing would end up looking something like this:
You need to read some good books on scripting first and then try
Thanks
Dipak Warade
I would recommend Bruce Blinn's "Portable shell programming, an extensive collection of bourne shell examples", along with Seebach's "Portable Shell Scripting: From Novice to Professional" and, ofcourse, Mendel Cooper's famous (and free!) book "Advanced bash scripting guide". And, if you want just a quick and dirty introduction, you can always have a look at "Bourne Shell Programming" by mister Robert P. Sayle (another free, online book).
These 2 Users Gave Thanks to vomv1988 For This Post:
Hi,
I have one script for which I want that other user should not read the script file but can execute. Is there any method ?
I tried by giving 711 but it gives Permission denied to other users.
For Generic User id as a work around , I have created alias in .bashrc file and other user... (4 Replies)
Hi,
can some one help me how to encrypt and decrypt a file.
AIM: reade user input, encrypt it and save it to file.
while decryption read the encrypted file decrypt it and save the output in some variable.
Example: consider we have Credentials.txt file with content username: password... (5 Replies)
Hi
I am new to writing script and want to use a Bash Piped while-read and read from user input.
if something happens on server.log then do while loop or if something happend on user input then do while loop.
Pseudocode something like:
tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Hi all ,
I need to know how to convert a time stamp entered by the user to be converted to GMT/UTC(epoch time) using mktime() and gmtime()
for exapample the input will be put in the form
ptm.tm_sec = 0;
ptm.tm_min = 59;
ptm.tm_hour = 11;
ptm.tm_mday = 20;... (2 Replies)
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'm making my first program with perl and am supposed to allow the user to either use the current date or enter a... (0 Replies)
hi all,
I have this file with some user data.
example:
$cat myfile.txt
FName|LName|Gender|Company|Branch|Bday|Salary|Age
aaaa|bbbb|male|cccc|dddd|19900814|15000|20|
eeee|asdg|male|gggg|ksgu|19911216|||
aara|bdbm|male|kkkk|acke|19931018||23|
asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
I am creating a menu driven system and i want to show the last login times of different users, instead of using the 'last' command i wanted to know if there is anyway i could make a brief search tool where the user can input which user they are looking for and then the login times for that specific... (2 Replies)
Hi ,
I m writing a program which involves piping(pipes).
In my program, once i execute the child process (dealing with pipe),I m not able to see any inputted command on the screen....but the entered command is getting executed...
Actaully inorder to implement piping i hav closed STDIN and... (3 Replies)
I need to create a shell script that takes 2 arguments, the first argument is any number, and the second argument is a filename. The script needs to indicate if the file's size is bigger or smaller than the number provided.
I know it will be some kind of if/then, but I can't figure out how to... (1 Reply)
Hi everybody,
Do you know how to hide the text for interactive unix shell script? Just like the case for inputting password during logon.
Patrick (1 Reply)