Sponsored Content
Top Forums Shell Programming and Scripting Storing lines of a file in a variable Post 302620935 by shamrock on Monday 9th of April 2012 01:52:12 PM
Old 04-09-2012
It wont if the echoed variable is double quoted...
Code:
VAR=$(tail -5000 file)
echo $VAR     # everything is mushed together
echo "$VAR"   # preserves newlines so nothing is mushed together

This User Gave Thanks to shamrock For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing value in a variable

Hi Everyone, I have a code which requires to be stored in different variables and I am achiving it like this. HOST=`echo $RMP | cut -f2 -d:` NAME=`echo $RMP | cut -f3 -d:` DIR=`echo $RMP | cut -f4 -d:` TYPE=`echo $RMP | cut -f5 -d:` Is there any other way of storing value... (2 Replies)
Discussion started by: gehlnar
2 Replies

2. Shell Programming and Scripting

About storing the value of wc -l into a variable and then using this value in while

Hi all, I m new to this forum. I ma facing onei issue. I have something like this: length= wc -l < b2| awk '{print $1}' where b2 is filename having detauls like: cat b2 abc1 abc4 xyc3 sbdghf4 but when I do echo "$length" it displays nothing Also I am using awk to overcome... (4 Replies)
Discussion started by: student2009
4 Replies

3. UNIX for Dummies Questions & Answers

Storing lines of output into a script variable

I'm sure this is a simple thing but I can't figure it out. In a script that I'm writing, I'd like to be able to store each line of output from "ls -l" into a variable. Ultimately I'd like to end up with something like: for a in `ls -l` do something with $a doneBut that's reading each... (2 Replies)
Discussion started by: ewoods
2 Replies

4. Shell Programming and Scripting

Storing the contents of a file in a variable

There is a file named file.txt whose contents are: +-----------------------------------+-----------+ | Variable_name | Value | +-----------------------------------+-----------+ | Aborted_clients | 0 | | Aborted_connects | 25683... (6 Replies)
Discussion started by: proactiveaditya
6 Replies

5. Shell Programming and Scripting

Reading from a file and storing it in a variable

Hi folks, I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it. My file is 1.txt and its contents are VERSION=5.6 UPDATE=4 I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)
Discussion started by: scriptfriend
6 Replies

6. Shell Programming and Scripting

storing a value from another file as a variable[solved]

Hi all, im having snags creating a variable which uses commands like cut and grep. In the instance below im simply trying to take a value from another file and assign it to a variable. When i do this it only prints the $a rather than the actual value. I know its simple but does anyone have any... (1 Reply)
Discussion started by: somersetdan
1 Replies

7. Shell Programming and Scripting

Storing multiple file paths in a variable

I am working on a script for Mac OS X that, among many other things, gets a list of all the installed Applications. I am pulling the list from the system_profiler command and formatting it using grep and awk. The problem is that I want to be able to use each result individually later in the script.... (3 Replies)
Discussion started by: cranfordio
3 Replies

8. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

9. UNIX for Beginners Questions & Answers

Storing file contents to a variable

Hi All, I was trying a shell script. I was unable to store file contents to a variable in the script. I have tried the below but unable to do it. Input = `cat /path/op.diary` Input = $(<op.diary) I am using ksh shell. I want to store the 'op.diary' file contents to the variable 'Input'... (12 Replies)
Discussion started by: am24
12 Replies

10. Shell Programming and Scripting

awk to compare each file in two directores by storing in variable

In the below bash I am trying to read each file from a specific directory into a variable REF or VAL. Then use those variables in an awk to compare each matching file from REF and VAL. The filenames in the REF are different then in the VAL, but have a common id up until the _ I know the awk portion... (15 Replies)
Discussion started by: cmccabe
15 Replies
SINCE(1)							   User Manuals 							  SINCE(1)

NAME
since - display content of a file since the last time SYNOPSIS
since [-aefhlmnqvxz] [-d seconds] [-s file] files DESCRIPTION
since is a utility designed to monitor log files. since is similar to tail(2) as it also displays information appended to a file. However since only displays the data which has been added since the last time since was run. If since is run on a particular file for the first time, then the entire file is displayed. EXAMPLE
since /var/log/apache/{access,error}_log > /dev/null lynx --dump http://localhost/ > /dev/null since /var/log/apache/{access,error}_log OPTIONS
-a Make updates to the since state files atomic. This option configures since to use a temporary file and a rename(2) instead of updat- ing the state file in situ. -d seconds Specify the number of integer seconds to wait between polling files for changes. This option is only relevant in conjunction with the -f option and if the inotify mechanism is not being used. -e Print the header lines to standard error instead of standard output. -f Follow the specified files. This option is analogous to tail -f as the files are also polled for changes until the process is inter- rupted. -h Print a terse help message. -l Relaxed mode. If some data files are inaccessible since will not fail completely. -m Disable mmap(2), use read(2) instead to access state and data files. Note that for certain smaller io operations read(2) may be used even if this option has not been given. -n Do not update the .since file which keeps track of file growth. -q Make the utility operate more quietly. -s filename Specify the state file explicitly. Using this option will also disable the use of fallback state files. -v Increase the verbosity. This option can be given multiple times. -x Ignore file arguments which have compressed extensions. -z Discard output. Similar to redirecting the output to /dev/null, but faster. If used in conjunction with the -f option, only the ini- tial output will be discarded. FILES
.since State file recording the length of the previously displayed files. The location of the file can be set on the command line using the -s option. If this option is not given, since will check the SINCE environment variable for the location of the state file. If the SINCE environment variable has not been set since will use the HOME environment variable and store the information in the file $HOME/.since. If the HOME variable is not set, since will use a getpwuid(3) lookup. If all these fail will use the file /tmp/since. BUGS
since uses the inode of a file as its key, if that inode is recycled since will get confused. since is not particularly efficient when storing or looking up the stat(2) information. Functionality equivalent to since can probably be achieved with a number of trivial shell scripts. COPYING
since may only be used, distributed and modified in accordance with the terms of the GPL (GNU General Public License) version 3 or newer as published by the FSF (Free Software Foundation). SEE ALSO
tail(1), stat(2). Linux JULY 1998 SINCE(1)
All times are GMT -4. The time now is 06:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy