Text Append


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text Append
# 1  
Old 04-05-2005
Text Append

I'm creating a script that counts the number of users currently online, then records that in a file called "log.txt" along with the time. Everytime the script is ran, the script appends the "log.txt"

this is what I have:

who|wc|cut -c6,7>>log.txt
date|cut -c12-24>>log.txt


After running the program, I checked the "log.txt" and this is what it had:

28
10:48:35 EDT


How will I make it so the "number of users" and "time" are beside each other in one line? (ex: 28 10:48:35 EDT)
# 2  
Old 04-05-2005
There's any number of ways that you can do this, though I must admit it sounds suspiciously like homework. So not to deviate to far from what you've already done:

WHO=`who | wc -l | sed -e"s/ * //g"`
NOW=`date|cut -c12-24`

echo "$WHO $NOW" >> log.txt

Cheers,

Keith
# 3  
Old 04-05-2005
It's not homework. Smilie I'm trying to learn unix on my own. I'm just playing around with making scripts. Thanks for the help! I actually learned pretty much DOS and everything else that has to do with computers by what I am doing right now with unix. Smilie
# 4  
Old 04-05-2005
Great. Sorry for my assumption. Look forward to your future posts.

Keith
# 5  
Old 04-05-2005
try this one ... (note the backticks in bold red) ...
Code:
echo "`who|awk 'END {print NR}'` `date|awk '{print $4, $5}'`" > log.txt

# 6  
Old 04-05-2005
got it! Thanks people! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to preserve the same text and modify the same text to append?

Hi, I have an issue modifying a file. Below is the content of the file. File name - a.txt SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*12 + 3), LISTAGG(DOB) from T_CONCAT ; SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*100 + 3), from... (1 Reply)
Discussion started by: Mannu2525
1 Replies

2. Shell Programming and Scripting

How to append a text file?

i have to append a text file grep for a word, if found, put comment in starting of the line. here is an example cat test.sh bin/ksh Hello World Test Message :wq! search for "bin" word in test.sh file if found comment it out at starting of the line: Output as follows: #bin/ksh... (5 Replies)
Discussion started by: raghur77
5 Replies

3. Shell Programming and Scripting

Use sed to append text to filenames if text not already present

I have some html with hrefs that contain local links to pdf filenames. These filenames should have standardised names, i.e. there should be a label prior to the ".pdf" filename suffix. There can be many of these links on a single line of text and some may already have the label. For example ... (13 Replies)
Discussion started by: adb
13 Replies

4. Shell Programming and Scripting

Search text and append using SED?

I have file . cat hello.txt Hello World I would like to append a string "Today " so the output is cat hello.txt Hello World Today I dont know which line number does the "Hello World" appears otherwise I could have used the Line number to search and append . (3 Replies)
Discussion started by: gubbu
3 Replies

5. Shell Programming and Scripting

Append text error?

Sup guys, today I tried to append a string from my text by asking the user to input and change the specific text they wanna append. The problem is that, the code looks logically correct, but when I run it there's an error somewhere. Can anyone identify for me? echo "Search data" read... (4 Replies)
Discussion started by: aLHaNz
4 Replies

6. Shell Programming and Scripting

Trying to search for a string and append text only once

Hi I am trying to search for a particular occurrence of a string in a file, and if found, append another string to the end of that line. Here is my file contents: column1 userlist default nowrite=3 output=4 column2 access default nowrite=3 Here is the code: A="user=1... (1 Reply)
Discussion started by: bludhemn
1 Replies

7. Shell Programming and Scripting

append each line with text

hi, I've a file with some text in it, i need to append few strings in the beginning and end of each row. --in file richie matt .. --out file hi, 'richie' is here hi, 'matt' is here ... I tried with awk command, but it fails because of ' Thanks (2 Replies)
Discussion started by: dvah
2 Replies

8. Shell Programming and Scripting

Cut and append the text

I have a text like this ... i need append the text whihc is after 'csb' into the end of the line input ----- sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl sdir;csp oc_lib-0.10.4;bdir;cbpdob ---enable-useosstl output sdir;csp os_lib-0.5.24;bdir;cbpdob ---enable-useosstl... (6 Replies)
Discussion started by: girija
6 Replies

9. UNIX for Dummies Questions & Answers

sed - append text to every line

Hi all I tried this on an old version of sed on NCR Unix MP-RAS: sed -e "s/$/nnn/" file1 >file2 This file (file1): the cat sat on the mat. the cat sat on the mat. the cat sat on the mat. becomes this (file2): the cat sat on the mat.nnn the cat sat on the mat.nnn nnn the... (3 Replies)
Discussion started by: jgrogan
3 Replies

10. Shell Programming and Scripting

how to append text into a file.

I have a command stream that will parse down an ftp DIR listing of a remote directory and return the name of the newest file that I am interested in. The command is sed -e '/^d/d' sppay.listing |sed -n -e '/SPPAY/p'|sort -r -k 43M,45 -k 47,48 -k 50,54|sed -n -e '1p'|cut -c 56-99 and what it... (2 Replies)
Discussion started by: beilstwh
2 Replies
Login or Register to Ask a Question