Extracting variables from echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting variables from echo
# 8  
Old 03-08-2010
Code:
sed 's/^ *//g'

This is used to remove the leading white spaces
# 9  
Old 03-08-2010
try this,

Code:
date | awk ' { print $3,$2,$6,$4 } '

# 10  
Old 03-08-2010
Quote:
I say chomp because I remember the perl variant.


I guess chomp remove the trailing \n? !!
# 11  
Old 03-08-2010
Ya, of course. So do you want to remove the trailing white space characters?
# 12  
Old 03-08-2010
You can use the following code
Code:
declare -a array
declare -a array1
array1=(3,2,6,4);
count=1;
for i in `date| cut -d ' ' -f 1-8`
do
        array[$count]=$i;
        ((count++))
done

for j in `echo ${array1}|tr ',' ' '`
do
        echo ${array[${j}]} ;
done

# 13  
Old 03-08-2010
You mentioned that, chomp because I remember the perl variant. chomp used to remove the trailing newline only.
If you want to remove the trailing newline try this,

Code:
sed -r 's/\n$//'  

(or)
sed -re 's/(.*)\n$/\1/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: passing shell variables through and extracting text

Hello, new to the forums and to awk. Glad to be here. :o I want to pass two shell (#!/bin/sh) variables through to awk and use them. They will determine where to start and stop text extraction. The code with the variables hard-coded in awk works fine; the same code, but with the shell... (7 Replies)
Discussion started by: bedtime
7 Replies

2. Shell Programming and Scripting

Echo not printing the variables with delimiters as required

This is the file which contains only neccessary values from the output of curl command i.e TEMP_FILE Proxy Hostname server0123.domain.com Proxy IP address XXX.XXX.XX.XX port 0000 Proxy Version SGOS X.X.X.X Proxy Serial # ... (5 Replies)
Discussion started by: ramprabhum
5 Replies

3. UNIX for Dummies Questions & Answers

Extracting a block of text from a large file using variables?

Hi UNIX Members, I've been tasked with performing the following: Extract a block of data in column form #This data changes each time, therefore automating future procedures Please Note the following: line = reading a line from a file_list that leads to the data The filename is called... (16 Replies)
Discussion started by: Klor
16 Replies

4. Shell Programming and Scripting

echo two variables like the paste command is not working

Dear all, I have two files like this file1 A B C D E F file2 1,2 3,4 5,6 I want this output output_expected A B 1,2 C D 3,4 E F 5,6 (3 Replies)
Discussion started by: valente
3 Replies

5. Shell Programming and Scripting

extracting substrings from variables

Hello Everyone, I am looking for a way to extract substrings to local variables. Here is the format of the string variable i am using : /var/x/www && /usr/x/share/doc && /etc/x/logs where the substrings i must extract are the "/var/x/www" and such. I was originally thinking of using... (15 Replies)
Discussion started by: jimmy75_13
15 Replies

6. Windows & DOS: Issues & Discussions

Extracting variables between commas : GAWK or SED

Hello, I need some help, I got a CSV file called test.txt with this text in it : 08/02/2011;0,677;0,903;1,079;1,336;1,513;1,683 There's only a line and i need to copy theese numbers into variables : 0,677 0,903 1,079 1,336 1,513 1,683 The output file should look like this... (5 Replies)
Discussion started by: jujulips
5 Replies

7. Shell Programming and Scripting

extracting multiple variables from a filename.

hi all, I'm trying to automate some tasks and while I've got the script itself working, I'm having difficulties with automatic file detection and associated variable setting... for example, in a directory I've got several files... something along the lines of: xis0_NAME_src.file... (2 Replies)
Discussion started by: u5j84
2 Replies

8. Shell Programming and Scripting

Echo Variables and Text

I've been trying to get the syntax right so I can echo a $var and then text around it or after it. It either wont display text or $var or one overwrites the other at the beginning of the line. Trying to do something like this. var=1 echo $var"+1.1" #output expected 1+1.1 Its an older... (3 Replies)
Discussion started by: Grizzly
3 Replies

9. Shell Programming and Scripting

Extracting a users environment variables

Hi Guys, I want to extract users environment variables via a sh script, and for some reason it is not working. According to the su man page: Example 3: Executing command with user bin's Environment and Permissions To execute command with the temporary environment and per-... (2 Replies)
Discussion started by: Tornado
2 Replies

10. UNIX for Dummies Questions & Answers

extracting return of ls -l into variables

If I do "ls -l filename" in a script, it should return something like this: -rw-r--r-- 1 user group 5945 Feb 28 14:24 filename How do I put each of the above strings into a different variable? eg Permissions, username, groupname, date (7 Replies)
Discussion started by: Sniper Pixie
7 Replies
Login or Register to Ask a Question