How Select numbers from a line of text, and remove leading spaces?
I have a text file with a line of text that contains numbers and text formatted into groups. I need to extract the number that can be either 1,2 or 3 digits long. Then write it to a variable, but i need to remove any leading spaces in the number first.
I can get the numbers out but how to remove the leading spaces?
My test file contents
My Script so far that will pull out the 3 digit number after the first C, and write it to a variable centnum
this is only part of the entire script as the rest will locate only the first line containing the neccessary value
the number in the output file needs to be just the significant digits and is a CSV so can be variable length.
I have tried using sed, but this just parses the entire file at once and I cannot process each line individually.
Hello and thx for reading this
I'm using sed to remove only the leading spaces in a file
bash-280R# cat foofile
some text
some text
some text
some text
some text
bash-280R#
bash-280R# sed 's/^ *//' foofile > foofile.use
bash-280R# cat foofile.use
some text
some text
some text... (6 Replies)
Dear All,
can you please advice how do i remove trailing and leading spaces from a pipe-delimited file using "tr" command
the below cmd, i tried removed all spaces
tr -d ' '<s1.txt>s2.txt1
Many thx
Suresh (5 Replies)
Hi Experts,
In a file tht i copied from the web , i am not able to remove the leading white spaces. I tried the below , none of them working . I opened the file through vi to check for the special characters if any , but no such characters found.
Your advice will be greatly appreciated.
sed... (5 Replies)
Hi All,
I have a vexing issue with leading spaces in file names. Basically, we're moving tons of data from our ancient afp file share to Box.com and Box forbids leading spaces in files or folders. The HFS file system seems to be perfectly fine with this, but almost all other Unix file systems... (1 Reply)
Hi,
I am trying to remove leading and trailing spaces from a file using awk but somehow I have not been able to do it.
Here is the data that I want to trim.
07/12/2017 15:55:00 |entinfdev |AD ping Time ms | .474| 1.41| .581|green |flat... (9 Replies)
OS : RHEL 6.7
Shell : bash
I am trying to remove the leading the spaces in the below file
$ cat pattern2.txt
hello1
hello2
hello3
hello4
Expected output is shown below.
$ cat pattern2.txt
hello1
hello2
hello3
hello4 (2 Replies)
Hi
I have variable named tablename. The value to tablename variable has leading and trailing white spaces. How to remove the leading and training white spaces and write the value of the tablename without space to a file using shell script. ( for e.g. tablename= yyy )
INPUT
... (10 Replies)
Hi,
At the moment, using Notepad++ to do a search and replace, manually section by section which is real painful. Yeah, so copying each section of the line of text and putting into a file and then search and replace, need at least 3-operations in Notepad++.
Here's hoping I will be able to... (1 Reply)
Discussion started by: newbie_01
1 Replies
LEARN ABOUT OPENSOLARIS
msggen
msggen(1) User Commands msggen(1)NAME
msggen - generate a machine independent formatted message catalog
SYNOPSIS
msggen [-fls] catfile [msgfile]
DESCRIPTION
msggen merges the message text source file msgfile into a machine independent formatted message catalog catfile. The file catfile is cre-
ated if it does not already exist. If catfile does exist, its messages are included in the new catfile. If set and message numbers collide,
the new message text defined in msgfile replaces the old message text currently contained in catfile.
Non-ASCII characters must be UTF-8 encoded. iconv(1) can be used to convert to/from UTF-8.
OPTIONS
The following options are supported:
-f List the printf(3C) format signature for each message in catfile. A format signature is one line containing one character for
--format each format specification:
c char
d double
D long double
f float
h short
i int
j long long
l long
p void*
s string
t ptrdiff_t
z size_t
? unknown
-l List catfile in UTF-8 msgfile form.
--list
-s Convert the catfile to a message set number and print the number on the standard output.
--set
OPERANDS
The following operands are supported:
catfile Machine independent formatted message catalog file.
msgfile Message text source file.
USAGE
Message text source files are in gencat(1) format, defined as follows. The fields of a message text source line are separated by a single
blank character. Any other blank characters are considered to be part of the subsequent field. The NL_* constants are defined in one or
both of <limits.h> and <nl_types.h>.
$ comment
A line beginning with a $ followed by a blank character is treated as a comment.
$delset n comment
This line deletes message set n from an existing message catalog. n denotes the set number [1, NL_SETMAX]. Any text following the set
number is treated as a comment.
$quote c
This line specifies an optional quote character c, which can be used to surround message-text so that trailing spaces or empty messages
are visible in a message source line. By default, or if an empty $quote directive is supplied, no quoting of message-text is recog-
nized.
$set n comment
This line specifies the set identifier of the following messages until the next $set or end-of-file (EOF) appears. n denotes the set
identifier, which is defined as a number in the range [1, NL_SETMAX]. Set numbers need not be contiguous. Any text following the set
identifier is treated as a comment. If no $set directive is specified in a message text source file, all messages are located in mes-
sage set 1.
$translation identification YYYY-MM-DD[,...]
Append translation information to the message catalog header. Only the newest date for a given identification is retained in the cata-
log. Multiple translation lines are combined into a single, comma-separated list.
m message-text
m denotes the message identifier, which is defined as a number in the range [1, NL_MSGMAX]. The message-text is stored in the message
catalogue with the set identifier specified by the last $set directive, and with message identifier m. If the message-text is empty,
and a blank character field separator is present, an empty string is stored in the message catalogue. If a message source line has a
message number, but neither a field separator nor message-text, the existing message with that number (if any) is deleted from the cat-
alogue. Message identifiers need not be contiguous. There are no message-text length restrictions.
EXIT STATUS
0 Successful completion.
>0 One or more specified jobs does not exist.
EXAMPLES
Example 1 Using msggen
The following example generates a message catalog xxx from the message file xxx.msg:
example% msggen xxx xxx.msg
AUTHORS
Glenn Fowler, gsf@research.att.com
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWastdev |
+-----------------------------+-----------------------------+
|Interface Stability |Volatile |
+-----------------------------+-----------------------------+
SEE ALSO gencat(1), iconv(1), msgcc(1), printf(3C), attributes(5)SunOS 5.11 9 Oct 2007 msggen(1)