Ubuntu :: Reading A Value From A Textfile Using Bash Script?

Jun 10, 2011

I have a text file that contains a single word and I want to write a bash script that will read the word from the text file... The following is my incorrect attempt, as it assigns the name of the textfile to the variable as opposed to the word stored within the textfile:(assume I have a text file value.txt that has as its contents a single word, say wordone)

#!/bin/sh
for f in value.txt
do
echo $f
done

so the output of the above script is value.txt, however I want it to be wordone.to summarise: how do I assign the value of the word contained within a textfile to a variable?

View 2 Replies


ADVERTISEMENT

Software :: Find A Word In A Textfile Starting From The BOTTOM Of The Textfile?

Feb 8, 2010

I have a text file example :

word1
word2
word4

[code]...

View 3 Replies View Related

General :: Bash - Subtract Contents Of One Textfile From Another

Jul 7, 2010

I have two text files on Linux. One contains a list of valid IDs. E.g:
abcd
efgh
ijkl
etc.

The other contains a list of invalid IDs. But, some of these also appear on the list of valid IDs, in this example "efgh":
mnop
qrst
efgh
etc.

How can I easily construct a text file that contains all the lines from the invalid list that do not appear in the valid list? That is, I want to end up with a text file that has:
mnop
qrst
etc.
I'd like either some Linux commandline magic of some clever Vim trickery.

View 3 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

General :: Bash: Reading File Into Array?

Dec 2, 2010

I have a file named file.txt with the following contents

Code:

19 man
24 house
44 dyam
90 random

I want to read the file into array and store each line in each index. I've tried using the following code.

Code:

dataarray=($( < file.txt ))

It stores each word in each index rather than each line in each index.

View 3 Replies View Related

General :: Reading File Into Variable In Bash?

Mar 21, 2011

I know that cat can output the file, but how do you store that output in a variable to process:

Code:

CONTENT=cat file.txt

This doesn't seem to work?

View 3 Replies View Related

Security :: Reading Encryption Password With Bash?

Nov 20, 2010

I have two cryptsetup volumes with the same password that I want to open in a bash script, and I want to avoid writing the passphrase twice. I was thinking of using read -s. Is there any security problems with this?The other alternative would be to have a password file on a small partition encrypted with a passphrase. Then only give the passphrase and let the script open up all encrypted volumes using the password file. However this seems overly complicated. But is it more secure?

View 3 Replies View Related

Programming :: Bash Reading Arguments, Most Effective Way?

Aug 17, 2010

I've been reading about getopt and getopts but it doesn't seem like it's possible to parse arguments like --foo or even -foo. I've started my own script trying to achieve this, but I'm still wondering if I'm losing performance and if there is a better way to do this task.

Also I'm using the [[ =~ ]] regex syntax which seems to be available only in newer bash versions, should it be a big issue? My bash version: GNU bash, version 4.1.7(2)-release (x86_64-unknown-linux-gnu)

[Code]...

View 6 Replies View Related

Programming :: Reading Files In A Directory Using Bash?

Nov 6, 2010

I am trying to write a simple script to list all the files in a directory. The script I wrote was as below where the pdb_files is a directory and all the files which I want to list are in that folder.

Code:
files=`ls -F pdb_files/*THERMO*`
for inFiles in $files
do
echo $inFiles

[Code]....

View 5 Replies View Related

Programming :: Reading From Text File In Bash?

Nov 8, 2010

I need to Read a path of a file witch is written in Text file i used this

Code:

FILENAME=$1
while read line
do
echo $line
done < $FILENAME

it worked and showed me the Line witch was written in my file but now my problem is how am gonna use that line as a path i mean for example if am gonna execute a linux command on that file like dpkg -i /path/to/the/file how am gonna export it from The $Line variable and use it after the command.

View 14 Replies View Related

Programming :: Reading File And Compare In Bash Scripts?

Dec 9, 2010

how to program in bash, an i have a problem, i am trying compare values in between 2 values (from another file), so far my solution is to make a nested for loop, but that causes it to compare every value. Here is a visulization of what i want

file.a 2,3,4,5
file.b
3 5

[code]...

i want the values 2, 3, 4, 5 from file.a to be compared inbetween values 3 5, 6 9,1 2, 4 7 from file.b (var1 is the value im comparing, var2 is the less value, var 3 is the greater value)

for i in $var1
do
for k in $var2
do

[code]....

my problem with the above code is it compares EVERYINNG, not the values inbetween what i want (which is 3 5, 6 9 etc).

View 8 Replies View Related

Programming :: Writing To And Reading From A Socket From Bash Script?

Mar 11, 2010

Here the description of the issue I am having.I am writing a bash test script which reads lines from a file, builds ISO messages, sends them to a server, reads the response with response code and reports the result of the test to a file or on the screen.The message that I need to send is 94 characters long.Here's the portion of a code that I initially wrote:

~ Open socket.
exec 3<>/dev/tcp/172.26.0.25/9991
#~ Send msg.

[code]...

View 7 Replies View Related

Programming :: Bash - Reading Csv Delimited File To Array And For Further Manipulation?

Jan 6, 2010

I am trying to do this:

1. Read csv delimited file line1 and store all values in array

2. Use the values stored in the array and replace values in other text file with them

3. read line2 in the cvs file and repeat the process

4. Do above for all lines in the cvs file

for example:

file1.cvs content:

text1,text2,text3,"text 4"
a1,a2,3,"a 4"

file.txt content:

some text $array1$ some text
some text $array2$ some text

1. read line 1 - text1,text2,text3,"text 4" put each value in array X[] lines that contain spaces in cvs will have double quotes

2. read x[1] and replace value $array1$ (in file.txt) with x[1]read x[2] and replace value $array2$ (in file.txt) with x[2] and so on

Can above be accomplished in BASH and how?

View 1 Replies View Related

Programming :: Reading File Permissions Into Bash Array For Processing

Dec 1, 2010

I would like to read unix file permissions into a bash array for processing but tbh I have no idea how to do this. Then I will check for each individual access right l, d, x etc.

View 11 Replies View Related

General :: Bash + Reading Values (numbers) From A File And Storing Them Into An Array?

Nov 4, 2010

I have to read a couple of numbers from a random.txt file. In this .txt file there are random numbers. They are separated by a space. Example if you opened test.txt:

test.txt :1 6 1 3 6 8 10 2 4

I would like to read those numbers using CAT and store them into an array:

numlen=${#num[*]} - (must be like this because it is a part of a larger program)

View 5 Replies View Related

Ubuntu :: PHP Value Of Variable Put Into A Textfile Using Unix?

Feb 1, 2011

How can I put a value of a php variable into a text file. I cant append or write the values into a text file.

View 2 Replies View Related

Programming :: Need To Save Textfile'$+1'.txt?

Apr 1, 2010

need a script to achieve saving multiple text files as 0001 0002 0003 etc.or moving files to a folder displayed this way..there prolly is an " if " statement involved also...if 0001 exist then %+1 and so on.

View 1 Replies View Related

Programming :: Bash Reading Multiple Files Line By Line?

Mar 8, 2011

I have a set of files containing data that I need to re-arrange into one single property list.

The files that I have look like this:

Code:
# cat uk
<string>10</string>
<string>11</string>
...
<string>29</string>

[Code]....

So the lines in the files match up but I haven't found a way of reading several files line by line.

View 3 Replies View Related

Programming :: Line By Line Reading And Writing In Bash?

Nov 29, 2010

I have a text file (myfile.txt) with columns a,b,c.

123 2 23
124 2 24
125 2 22

[code]...

View 4 Replies View Related

General :: Parse A Textfile To Move Some Files?

Mar 9, 2010

I use avg free as antivirus scanner. I looked some time for a scanner to scan and remove viruses. Problem is avg 8.5 will only detect viruses, not remove them...I use a oneliner looking like this:

Code:
/usr/bin/avgscan / -x /mnt -x /dev --heur --ignerrors -r /var/log/"scanlog"`eval date +%Y%m%d`".txt"

[code]...

View 5 Replies View Related

General :: Save Each Line From Textfile As New File?

Jul 4, 2011

just started with Linux and I'm trying to create new files for each line of my input file. So I have file with 637 lines of data:

2 4 6
2 8 5
3 0 5
etc

and want to create a new file from each line. With

cat name.txt | awk '{ line = $0
print line
}'

I nicely see all lines, but what rests is to save each line separately into new file. I tried While read line command in combination with output >> $.txt, but didn't work well..

View 8 Replies View Related

Ubuntu Networking :: Broadcom On 2.6.34 - Reinstall Error Code: Reading Package Lists ... Done Building Dependency Tree Reading State Information

May 20, 2010

i installed kernel 2.6.34 to fix my lid closing issue, and that went great. but now when i go to reinstall my broadcom i get this error. Code: Reading package lists... Done Building dependency tree Reading state information... Done bcmwl-kernel-source is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. 1 not fully installed or removed. After this operation, 0B of additional disk space will be used. Setting up bcmwl-kernel-source (5.60.48.36+bdcom-0ubuntu3) ... Removing old bcmwl-5.60.48.36+bdcom DKMS files...

[Code].....

View 9 Replies View Related

Programming :: Awk - Calculate The Number Of Words Containing Letter E In A Textfile?

Oct 12, 2010

i need to calculate the number of words containing letter e in a textfile.

View 9 Replies View Related

General :: Why Is Reading A FILE Faster Than Reading A VARIABLE?

May 4, 2011

I don't understand the results of a simple performance test I ran using two basic scripts (running on a high end server):

perfVar.zsh :

#!/bin/zsh -f
MYVAR=`cat $1`
for i in {1..10}

[code]...

Performance test result:

> time ./perfVar.zsh BigTextFile > /dev/null
./perfVar.zsh FE > /dev/null 6.86s user 0.32s system 100% cpu 7.177 total
> time ./perfCat.zsh BigTextFile > /dev/null
./perfCat.zsh FE > /dev/null 0.01s user 0.10s system 91% cpu 0.118 total

I would have thought that accessing a VARIABLE was way faster than reading a FILE on the file system... Why this result ?Is there a way to optimize the perfCat.zsh script by reducing the number of accesses to the file system ?

View 3 Replies View Related

Ubuntu :: Terminal Bash / -bash: Ls: Command Not Found

Jun 5, 2011

I got a problem with terminal, since i'm really a noob with terminal i don't know how to fix it.Everytime i type in a command it shows for example:

-bash: ls: command not found

Even the basic commands don't work... just cd <directory> and those things works

View 9 Replies View Related

Programming :: Bash: Printing The Line Number In Bash Script?

Feb 4, 2011

I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.

View 3 Replies View Related

General :: Write A Literal Bash Command In A Bash File?

Nov 29, 2010

I create a bash script that writes another bash file. But in the generated bash file I want to write a bash command in the file and not executing it.Here's my bash file:

Code:
#!/bin/bash
cat > ~/generateGridmix2data.sh << END

[code]...

View 6 Replies View Related

General :: Running Bash But Common Bash Commands Not Working?

Jul 17, 2010

below are the details of my system. I have bash as my current shell, some really common commands aren't working.

Do I need to do a re-installation of bash? Or how do I install a selection of bash commands which I need? (for example a subset of [URL])

Code:
root@sdptfw:~ # uname -a
Linux sdptfw.sdpt.co.za 2.4.36 #1 Tue Jul 22 13:13:24 GMT 2008 i686 i686 i386 GNU/Linux
root@sdptfw:~ # echo $SHELL$
/bin/bash$

[Code]....

View 13 Replies View Related

Programming :: Bash Ctrl+c Tarp And Bash Read With Timeout?

Jan 24, 2010

simple bash code:

Code:
#!/bin/bash
trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c
echo "Press ctrl+c during 5 sec loop"
for ((i=0;i<5;i++)); do

[Code]...

How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!

View 10 Replies View Related

Programming :: Run Multiple Bash And Php Scripts From A Bash Script?

Jul 25, 2011

I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.

Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved