Sponsored Content
Top Forums Shell Programming and Scripting How Select numbers from a line of text, and remove leading spaces? Post 302844266 by kcpoole on Sunday 18th of August 2013 04:09:15 AM
Old 08-18-2013
Thanks and that almost works. I get the 1, 2 or 3 numbers as desired but when I write them out to a resulting file using this line, I now get a space after the numbers.
Code:
echo D';'$centnum';'$centnam';;M;;' > MM_file.txt

Code:
D;156 ;Home athletics center;;M;;

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove leading spaces from a line

Hi friends I need some help, I have a file which looks as follows TEMP 014637065 014637065 517502 517502 RTE 517502 517502 RTE AWATER_TEST 12325 23563 588323 2323 5656 32385 23235635 ANOTHER_TEST 12 5433 FTHH 5653 833 TEST 123 123 3235 5353 353 53 35 353 535 3 YTERS GJK JKLS ... (6 Replies)
Discussion started by: lijojoseph
6 Replies

2. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

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)
Discussion started by: laser
6 Replies

3. Shell Programming and Scripting

remove trailing and leading spaces using tr command

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)
Discussion started by: sureshg_sampat
5 Replies

4. Shell Programming and Scripting

Not able to remove leading spaces

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)
Discussion started by: panyam
5 Replies

5. OS X (Apple)

Remove leading spaces from file names and folders

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)
Discussion started by: prometheon123
1 Replies

6. UNIX for Beginners Questions & Answers

How do I remove leading spaces in UNIX when count of space character is not fixed? Example below-

Script showStreamsGLIS$reg.$env.ksh gives me output as below- Job Stime Etime Status ExitCode GLIS-AS-S-EFL-LOCK-B ----- ----- OI 103313880/0 GLIS-ALL-Q-EOD-FX-UPDT-1730-B ----- ----- TE 0/0 GLIS-TK-S-BWSOD-B ... (8 Replies)
Discussion started by: Tanu
8 Replies

7. Shell Programming and Scripting

Remove leading and trailing spaces from a file

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)
Discussion started by: svajhala
9 Replies

8. Shell Programming and Scripting

Trying to remove leading spaces

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)
Discussion started by: John K
2 Replies

9. Shell Programming and Scripting

How to remove leading and trailing spaces for variable in shell script?

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)
Discussion started by: pottic
10 Replies

10. UNIX for Beginners Questions & Answers

Tip to remove line endings and spaces on a pre-formatted text file?

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
mkcatdefs(1int) 														   mkcatdefs(1int)

Name
       mkcatdefs - Preprocesses a message source file

Syntax
       mkcatdefs symbol_name source_file ...

Description
       The message facility program preprocesses a message source file. The source_file message text source file contains mnemonic identifiers.

       The  program  produces  the symbol_name_msg.h file containing definition statements equating your mnemonic identifiers with set numbers and
       message ID numbers assigned by The symbol_name _msg.h file is required in your application program if you use mnemonic identifiers.

       The program sends message source data, with numbers instead of mnemonic identifiers, to standard output. This output is suitable  as  input
       to  the program. You can use the > (redirection mnemonic) to write the message source to a file, then use the file as input to You can cre-
       ate a message text source file using any text editor to enter the messages.

       Assign message set numbers and message ID numbers to each message by using the commands described in the following section.

   Symbolic Message Identifiers
       The operating system provides a mechanism that allows mnemonic references to messages by letting you use alphanumeric  identifiers  instead
       of  set	numbers  and  message  ID  numbers. You assign the identifiers to sets and messages in the source file in the same manner that you
       assign set numbers and message ID numbers.

       The mnemonic identifiers can contain ASCII letters, digits, and underscores. The first character cannot be a digit. The maximum length can-
       not exceed 64 bytes.

       The following example shows a message source file with mnemonic message identifiers:
       $set symbolic	  Message Facility - Symbolic ID's
       $quote *
       ID_names  *Symbolic identifier syntax: 
 
       	ASCII alphanumerics or underscores 
 
       	non-digit first character 
 
       	64 byte maximum length *
       set_use	 *To assign set ID: 
 
       	$set "identifier" [comment] *
       msg_use	 *To assign message ID: 
 
       	"identifier" message-text *

   Subcommands
       Use the $set command in a source file to give a group of messages a set number. The format of the $set command is as follows:
       $ set n [ comment ]
       The  set number is specified by n. Instead of a number, you can specify a mnemonic identifier that must contain only ASCII letters, digits,
       or the _ (underscore character). The maximum length of an identifier is 65 bytes. The program assigns a set number to the  identifier.  The
       assigned  set  number  is one higher than the preceding set number, or 1 if it is the first $set.  The program inserts a $delset before the
       $set in the output message source file.

       You can mix numbers and mnemonic identifiers.  You can include a comment in the $set command, but it is not required. The following example
       includes a comment:
       set CEM	Communication Error Messages
       Use  the  $delset command to remove all of the messages belonging to the specified set from a catalog. The format of the $delset command is
       as follows:
       $delset n [ comment ]

       The message set is specified by n. The $delset command must be placed in the proper set number order with respect to any $set  commands	in
       the same source file. You can include a comment in the $delset command also.

       You can include a comment line anywhere in the source file, except within message text. Indicate comments as follows:
       $ [ comment ]

       You must leave at least one space after the $ prompt.

       Enter the message text and mnemonic message identifier as follows:
       identifier message_text

       identifier  can	be  either a number or a mnemonic identifier and can contain only ASCII letters, digits, or the _  (underscore character).
       The maximum length of an identifier is 65 bytes. The program assigns a message number to the identifier. The assigned number is one  higher
       than the preceding message number, or 1 if it is the first message after the $set command.

       Note that inserts a $delset before the $set, which means you cannot add, delete, or replace single messages in the catalog if you are using
       mnemonic message identifiers. You must enter all of the messages in the set.

       You can mix numbers and mnemonic identifiers.

       You must leave at least one space after the message identifier or number.

       Any amount of white space is allowed after the message ID number; however, X/Open specifies that you leave only one space between the  mes-
       sage  number  and the message text. All text following the first nonspace character to the end of the line is included in the message text.
       If the source contains a $quote command preceding the message, all text between the quotation marks is included. Use a  (backslash)  char-
       acter to continue message text on the following line.  The  must be the last character on the line, as in the following example:
       FIVE	Text associated with 
       message FIVE.
       These two lines define the following single-line message:
       FIVE	Text associated with message FIVE.
       The  can be used to include special characters in the message text. These special characters are defined as follows:

       
     Inserts a newline character.

       	     Inserts a horizontal tab character.

       v     Inserts a vertical tab.

            Inserts a backspace character.

       
     Inserts a carriage-return character.

       f     Inserts a formfeed character.

       \     Inserts a  (backslash) character.

       ddd   Inserts  the  single-byte  character  associated with the octal value represented by the valid octal digits ddd.	One, two, or three
	      octal digits can be specified; however, you must include leading zeros if the characters following the octal digits are  also  valid
	      octal  digits.  For example, the octal value for $ is 44. To display $5.00, use 445.00, not 445.00, or the 5 is parsed as part of
	      the octal value.

       You can also include conversion specifications in messages that are displayed by applications using You can use the  $quote  command  in  a
       message source file to define a character for delimiting message text. The format for this command is as follows:
       $quote [ char ] [ comment ]

       Use the specified character before and after the message text as shown in the following example source file:
       $quote "  Use a double quotation mark to delimit message text
       $set MSFAC	  Message Facility - symbolic identifiers
       SYM_FORM   "Symbolic identifiers can only contain ASCII letters 
       or digits or the _ (underscore character)
"
       SYM_LEN	  "Symbolic identifiers cannot be more than 65 
       bytes long
"
       5	      "You can mix symbolic identifiers and numbers 
"
       $quote
       MSG_H	 Remember to include the "msg_h" file in
       your program


       In  this example, the $quote command sets the quote character to " (double quote), then disables it before the last message, which contains
       double quotes.

       The preceding file can be processed with as follows:

       $ mkcatdefs symb symb.src >symb.msg

       When you process the file with the modified source is written to standard output.  Standard output can either be redirected to a file using
       the > (redirection mnemonic) or piped to

       The following source is created:
       $quote "     Use double quotation marks to delimit message text
       $delset 1
       $set 1
       1     "Symbolic identifiers can only contain ASCII letters 
       or digits or the _ (underscore character)
"
       2     "Symbolic identifiers cannot be more than 65 
       bytes long
"
       5     "You can mix symbolic identifiers and numbers
"
       $quote
       6     remember to include the "msg_h" file in your program

       Note  that  the	assigned  message numbers are noncontiguous because the source contained a specific number. The program always assigns the
       previous number plus 1 to a mnemonic identifier.

       The program also produces a definition file for inclusion in your program.  The name of the file is symbol_name,  and  is  entered  as  the
       first argument to the command.

Examples
       If the message text source defined under Subcommands were in a file called symb.src, you could use the command as follows:
       $ mkcatdefs symb symb.src >symb.msg
       or
       $ mkcatdefs symb symb.src | gencat symb.cat
       The generated symb_msg.h file would appear as follows:
       #ifndef _H_SYMB_MSG
       #define _H_SYMB_MSG
       #include <limits.h>
       #include <nl_types.h>
       #define MF_SYMB "symb.cat"
       /* The following was generated from symb.src. */
       /* definitions for set MSFAC */
       #define MSFAC 1
       #define SYM_FORM 1
       #define SYM_LEN 2
       #define MSG_H 6
       Note  that  also created  a mnemonic MF_SYMB by adding MF_ to the symbol_name using uppercase letters. The program assumes that the name of
       the generated catalog should be symbol_name.cat, and generates this mnemonic for your use with The symbol_name.cat file	includes  limits.h
       and  nl_types.h, you do not need to include them in your application program.  (nl_types defines special data types required by the message
       facility routines.)

See Also
       extract(1int), gencat(1int), trans(1int), catgets(3int), catopen(3int), environ(5int)
       Guide to Developing International Software

																   mkcatdefs(1int)
All times are GMT -4. The time now is 02:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy