Sponsored Content
Top Forums Shell Programming and Scripting Command output string manipulation possible in one line? Post 302545021 by Ryan. on Friday 5th of August 2011 09:56:23 PM
Old 08-05-2011
Command output string manipulation possible in one line?

This has been bothering me for 3 days.

$> hostname
cepsun64amd

And I just want "cepsun",

I would normally do h=`hostname`; ${h%%64*}

But I am looking for a one-liner just for my own knowledge, because if there is a way to do this, I should know it by now.

Anyway, so is this possible?

P.S. I realize there are other ways to do this without using ${%%}, but I have ran into this problem like 4 times within the past few days where it would be really convenient and clean to just use ${VAR%%PATTERN}.

Thanks
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to? launch command with string of command line options

my description from another thread... here's my code: #!/bin/bash IFS=$'\n' function OutputName() { input=$1 echo $input input=`echo "$input" | sed -e 's/.//'` input=`echo "$input".avi` output_name=$input } if ]; then echo... (5 Replies)
Discussion started by: TinCanFury
5 Replies

2. Shell Programming and Scripting

reading ps command's output line by line

hi; as a pseudo; while read psLine do myFunc $psLine done < ps i don't want to redirect ps command's to a file. in fact, my problem is "how can i read stdout line by line in bash, sed, awk or any?" thanks, (5 Replies)
Discussion started by: s. murat
5 Replies

3. Shell Programming and Scripting

Remove a specific line from grep output string

Dear All I want to search string "1000" from input file and if it found i want remove line that contain 1000 and also remove 3 line above it and 2 line below it. INPUT FILE: BHAT-D 2 aaa ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES 50 ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

4. Shell Programming and Scripting

grep only a string on command output

How can I grep exactly a string that has .,/ characters using grep? Example: I want to grep ONLY string1 and not string1.more or string1.more.evenmore #lsauth ALL|grep 'string1' All output: string1 <--- This is the only I want. string1.more string1.evenmore. more.string1... (4 Replies)
Discussion started by: iga3725
4 Replies

5. Shell Programming and Scripting

Bash - Loading a command's output line by line into an array

I have been trying this a lot of different ways and haven't found too much online. Here's what I've got so far: j=0 declare -a first zero=(`cat $tmpfile`) for i in "${zero}" do command $i >> "${first}" ... (4 Replies)
Discussion started by: Azrael
4 Replies

6. Shell Programming and Scripting

Want to terminate command execution when string found in the command output

Hi Experts, I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task. I am running below command to snmpwalk the router.. snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
Discussion started by: Hanumant.madane
19 Replies

7. Shell Programming and Scripting

Manipulation of file/folder with output of command

I like organising some of my folders in the format of yyyymmdd to keep them in chronological order. For example, today which is 5th July 2014, I made a folder named 20140705. I want to manipulate these folders from a shell script, but I cannot find out how to do it without typing the literal name... (5 Replies)
Discussion started by: Gen12345
5 Replies

8. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

9. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies
PMHOSTNAME(1)						      General Commands Manual						     PMHOSTNAME(1)

NAME
pmhostname - report hostname SYNOPSIS
$PCP_BINADM_DIR/pmhostname [hostname] DESCRIPTION
pmhostname reports the name of the host hostname as returned by gethostbyname(3N). If hostname is not specified, then the local host name is retrieved using gethostname(2) and this is than passed to gethostbyname(3N). pmhostname provides a service for shell scripts that mimics the logic formerly used by Performance Co-Pilot applications when trying to determine the official name of a host. PCP applications no longer use DNS-based heuristics, and therefore this command is deprecated. If gethostbyname(3N) fails, the input host name (either hostname or the result from calling gethostname(2)) is reported. PCP ENVIRONMENT
Environment variables with the prefix PCP_ are used to parameterize the file and directory names used by PCP. On each installation, the file /etc/pcp.conf contains the local values for these variables. The $PCP_CONF variable may be used to specify an alternative configura- tion file, as described in pcp.conf(5). SEE ALSO
named(1), nsd(1), nslookup(1), gethostname(2), gethostbyname(3N), pcp.conf(5), pcp.env(5) and resolver(5). Performance Co-Pilot PCP PMHOSTNAME(1)
All times are GMT -4. The time now is 11:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy