Sponsored Content
Top Forums Shell Programming and Scripting (g)awk how to preseve white spaces (FS characters) or read a right subpart of $0? Post 302338617 by shri_nath on Tuesday 28th of July 2009 11:44:09 AM
Old 07-28-2009
Hi radoulov,

Quote:
Originally Posted by radoulov
You know that the filename will be after the 7th field,
so you could do something like this:

Code:
gawk --posix 'NR > 2 && !/\/$/ {
  sub(/([^ \t]+[ \t]+){7}/,"")
  print
  }' infile

This is the best answer. I had also come to the same pattern, but albeit separately for each of the first seven fields. Your answer is even better. I am going to change it a little bit as follows:

Code:
     gsub(/^([^ \t]+[ \t]+){6}[^ \t]+ /, "", fileName);

for the obvious reason that fileName itself could start with a white space!
Could you suggest me a pattern that would also get rid of the very last (one or zero) characters from these: />*|@= ?

I tried
Code:
    gsub(/^([^ \t]+[ \t]+){6}[^ \t]+ (.+)[\/\>\*\|\@\=]{0,1}$/, "\\1", fileName);

but that did not work and so I am having the above left most seven fields removed first and then followed by another to gsub to remove the (zero or one) of those last charcters.
Thanks.

-sn
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

deleting white spaces

How would I delete white spaces in a specified file? Also, I'd like to know what command I would use to take something off a regular expression, and put it onto another. ie. . . . expression1 <take_off> . . . expression2 (put here) . . . Any help would be great, thanks! (10 Replies)
Discussion started by: cary530
10 Replies

2. Shell Programming and Scripting

delete white spaces

hi all... i have the next question: i have a flat file with a lot of records (lines). Each record has 10 fields, which are separated by pipe (|). My problem is what sometimes, in the first record, there are white spaces (no values, nothing) in the beginning of the record, like this: ws ws... (2 Replies)
Discussion started by: DebianJ
2 Replies

3. Shell Programming and Scripting

Trim white spaces using awk

Hi, I have a CSV file with footer information as below. The third value is the number of records in the file. Sometimes it contains both leading and trailing white spaces which i want to trim using awk. C,FOOTER , 00000642 C,FOOTER , 00000707 C, FOOTER,... (2 Replies)
Discussion started by: mona
2 Replies

4. Shell Programming and Scripting

trimming white spaces

I have a variable that calls in a string from txt file. Problem is the string comes with an abundance of white spaces trailing it. Is there any easy way to trim the tailing white spaces off at the end? Thanks in advance. (9 Replies)
Discussion started by: briskbaby
9 Replies

5. UNIX for Dummies Questions & Answers

Replace only first found white spaces with some other characters

Anybody can help me How can I replace only four first white spaces with , or any other characters aaaa 08/31/2004 08/31/2009 permanent Logical Processors in System: 64 bedad 08/16/2001 08/15/2011 permanent Logical Processors in System: 64 badnv14 05/31/2008 05/30/2013 permanent Logical... (5 Replies)
Discussion started by: pareshan
5 Replies

6. Solaris

removing special characters, white spaces from a field in a file

what my code is doing, it is executing a sql file and the resullset of the query is getting stored in the text file in a fixed format. for that fixed format i have used the following code:: Code: awk -F":"... (2 Replies)
Discussion started by: priyanka3006
2 Replies

7. Shell Programming and Scripting

Leading white spaces

Hi, I am having problem in deleting the leading spaces:- cat x.csv baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played $ nawk 'BEGIN{FS=","}!a... (2 Replies)
Discussion started by: scripter12
2 Replies

8. AIX

Replace all TAB characters with white spaces

Dear Gurus Can you please advise me on how to Replace all TAB characters with white spaces in a text file in AIX? Either using vi or any utilities (2 Replies)
Discussion started by: tenderfoot
2 Replies

9. Shell Programming and Scripting

Bash - read white spaces

Hello! I have one problem with my bash script - I would like to be able to read white space characters from stdin (for example single " ") - can I acomplish that somehow? I need to read only one character at the time, so I use read -s -n 1 var but it doesn't work for whitespaces apparently. ... (3 Replies)
Discussion started by: xqwzts
3 Replies

10. Shell Programming and Scripting

Removing blank/white spaces and special characters

Hello All , 1. I am trying to do a task where I need to remove Blank spaces from my file , I am usingawk '{$1=$1}{print}' file>file1Input :- ;05/12/1990 ;31/03/2014 ; Output:- ;05/12/1990 ;31/03/2014 ;This command is not removing all spaces from... (6 Replies)
Discussion started by: himanshu sood
6 Replies
load(n) 						       Tcl Built-In Commands							   load(n)

__________________________________________________________________________________________________________________________________________________

NAME
load - Load machine code and initialize new commands. SYNOPSIS
load fileName load fileName packageName load fileName packageName interp _________________________________________________________________ DESCRIPTION
This command loads binary code from a file into the application's address space and calls an initialization procedure in the package to incorporate it into an interpreter. fileName is the name of the file containing the code; its exact form varies from system to system but on most systems it is a shared library, such as a .so file under Solaris or a DLL under Windows. packageName is the name of the package, and is used to compute the name of an initialization procedure. interp is the path name of the interpreter into which to load the package (see the interp manual entry for details); if interp is omitted, it defaults to the interpreter in which the load command was invoked. Once the file has been loaded into the application's address space, one of two initialization procedures will be invoked in the new code. Typically the initialization procedure will add new commands to a Tcl interpreter. The name of the initialization procedure is determined by packageName and whether or not the target interpreter is a safe one. For normal interpreters the name of the initialization procedure will have the form pkg_Init, where pkg is the same as packageName except that the first letter is converted to upper case and all other letters are converted to lower case. For example, if packageName is foo or FOo, the initialization procedure's name will be Foo_Init. If the target interpreter is a safe interpreter, then the name of the initialization procedure will be pkg_SafeInit instead of pkg_Init. The pkg_SafeInit function should be written carefully, so that it initializes the safe interpreter only with partial functionality provided by the package that is safe for use by untrusted code. For more information on Safe-Tcl, see the safe manual entry. The initialization procedure must match the following prototype: typedef int Tcl_PackageInitProc(Tcl_Interp *interp); The interp argument identifies the interpreter in which the package is to be loaded. The initialization procedure must return TCL_OK or TCL_ERROR to indicate whether or not it completed successfully; in the event of an error it should set the interpreter's result to point to an error message. The result of the load command will be the result returned by the initialization procedure. The actual loading of a file will only be done once for each fileName in an application. If a given fileName is loaded into multiple interpreters, then the first load will load the code and call the initialization procedure; subsequent loads will call the initialization procedure without loading the code again. It is not possible to unload or reload a package. The load command also supports packages that are statically linked with the application, if those packages have been registered by calling the Tcl_StaticPackage procedure. If fileName is an empty string, then packageName must be specified. If packageName is omitted or specified as an empty string, Tcl tries to guess the name of the package. This may be done differently on different platforms. The default guess, which is used on most UNIX platforms, is to take the last element of fileName, strip off the first three characters if they are lib, and use any following alphabetic and underline characters as the module name. For example, the command | load libxyz4.2.so uses the module name xyz and the command load bin/last.so {} uses the module name last. If fileName is an empty string, then packageName must be specified. The load command first searches for a statically loaded package (one | that has been registered by calling the Tcl_StaticPackage procedure) by that name; if one is found, it is used. Otherwise, the load com- | mand searches for a dynamically loaded package by that name, and uses it if it is found. If several different files have been loaded with | different versions of the package, Tcl picks the file that was loaded first. PORTABILITY ISSUES
Windows When a load fails with "library not found" error, it is also possible that a dependent library was not found. To see the dependent libraries, type ``dumpbin -imports <dllname>'' in a DOS console to see what the library must import. When loading a DLL in the cur- rent directory, Windows will ignore ``./'' as a path specifier and use a search heuristic to find the DLL instead. To avoid this, load the DLL with load [file join [pwd] mylib.DLL] BUGS
If the same file is loaded by different fileNames, it will be loaded into the process's address space multiple times. The behavior of this varies from system to system (some systems may detect the redundant loads, others may not). SEE ALSO
info sharedlibextension, Tcl_StaticPackage(3), safe(n) KEYWORDS
binary code, loading, safe interpreter, shared library Tcl 7.5 load(n)
All times are GMT -4. The time now is 09:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy