Sponsored Content
Contact Us Post Here to Contact Site Administrators and Moderators How to read the nth character from the line.? Post 303009746 by RudiC on Tuesday 19th of December 2017 10:27:36 AM
Old 12-19-2017
Welcome to the forum.

You've been told twice already to
- follow the rules.
- post in an adequate forum - certainly not "Post Here to Contact Site Administrators and Moderators".
- post homework ONLY in https://www.unix.com/homework-coursework-questions/ and fill in the form completely.
- use code tags

Sorry, this thread is closed again.
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read First Character of Each Line in File

I need a better way to read the first character of each line in a file and check if it equals the special character ¤. This character tells me where there is a break in the reports. The file has over 500,000 lines. Currently, this is my code - if ] I am using Korn Shell as a scripting... (7 Replies)
Discussion started by: azelinsk
7 Replies

2. Shell Programming and Scripting

Read line based on character,

Hi Experts, I have called file1.txt contains below CREATE TABLE "IHUBDEV2"."TLM_BREAK_RULES" ( "OID" VARCHAR2(32) NOT NULL ENABLE, "TLM_PAY_CLASS_OID" VARCHAR2(32) NOT NULL ENABLE, "PUNCHED_BREAKS" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE, "NORMAL_BREAKS"... (3 Replies)
Discussion started by: naree
3 Replies

3. Shell Programming and Scripting

Read last word of nth line

Hi people; i want to read the last word of the 14th line of my file1.txt. Here is the EXACT 14th line of the file. 250 SectorPortnum=3,AuxPortInUngo=2,PortDeviceGroup=1,PortDeviceSet=1,PorDevice=1 20 >>> Set. i have to get the word Set. how can i call it and also how... (3 Replies)
Discussion started by: gc_sw
3 Replies

4. Shell Programming and Scripting

How to read one character form each line of the file?

Hi, Maybe this iscorrect forum for my question... I should read one character at a fixed position from each line of the file. So how ??? should be substituted in the code below: while read line ; do single_char=`???` echo "$single_char" done < $input_file OK...I did get an... (0 Replies)
Discussion started by: arsii
0 Replies

5. Shell Programming and Scripting

Read file from nth line to specific character

Hi, I want to read the file from nth line (where n is an integer) to until I encounter @ char. Can any one please help me how to do this? Thanks. (3 Replies)
Discussion started by: laalesh
3 Replies

6. Shell Programming and Scripting

Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation? I have a data file that is in the format of 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

7. Shell Programming and Scripting

Read a file from the nth line on

I have a script which reads from a job file and executed the scripts in the job file in sequence. #! /bin/ksh set -x while read line do $line.ksh if # mail the team fi done <"$file" The job file will be like abcd efgh ijkl mnop qrst This is working fine. I need to add... (2 Replies)
Discussion started by: nw2unx123
2 Replies

8. Shell Programming and Scripting

Search and recursively enter new line after Nth character

Hi All, My file is a string of around 50K character. I'm trying to insert new line after every 320 character in my file. I know the command to insert newline, but problem is I'm not able to search 320th position. Please advice. (6 Replies)
Discussion started by: Amit786
6 Replies

9. Shell Programming and Scripting

Read character by character in line in which space is also included

Hi friend, I have one file , and i want to read that file character by character. I need this script in ksh. while using read option with -n1 am getting error. while read -n1 c read has bad option And if i am using below script, then if in a line has space like this ( Pallvi mahajan)... (10 Replies)
Discussion started by: pallvi_mahajan
10 Replies

10. Shell Programming and Scripting

Replace nth to nth character?

Hi I got the following problem and I wonder if some could please help me out? I'd like to replace character 8 - 16 , 16 - 24 cat file ... (2 Replies)
Discussion started by: stinkefisch
2 Replies
JudyHS(3)						     Library Functions Manual							 JudyHS(3)

NAME
JudyHS macros - C library for creating and accessing a dynamic array, using an array-of-bytes of Length as an Index and a word as a Value. SYNOPSIS
cc [flags] sourcefiles -lJudy #include <Judy.h> Word_t * PValue; // JudyHS array element int Rc_int; // return flag Word_t Rc_word; // full word return value Pvoid_t PJHSArray = (Pvoid_t) NULL; // initialize JudyHS array uint8_t * Index; // array-of-bytes pointer Word_t Length; // number of bytes in Index JHSI( PValue, PJHSArray, Index, Length); // JudyHSIns() JHSD( Rc_int, PJHSArray, Index, Length); // JudyHSDel() JHSG( PValue, PJHSArray, Index, Length); // JudyHSGet() JHSFA(Rc_word, PJHSArray); // JudyHSFreeArray() DESCRIPTION
A JudyHS array is the equivalent of an array of word-sized value/pointers. An Index is a pointer to an array-of-bytes of specified length: Length. Rather than using a null terminated string, this difference from JudySL(3) allows strings to contain all bits (specifically the null character). This new addition (May 2004) to Judy arrays is a hybird using the best capabilities of hashing and Judy methods. JudyHS does not have a poor performance case where knowledge of the hash algorithm can be used to degrade the performance. Since JudyHS is based on a hash method, Indexes are not stored in any particular order. Therefore the JudyHSFirst(), JudyHSNext(), JudyH- SPrev() and JudyHSLast() neighbor search functions are not practical. The Length of each array-of-bytes can be from 0 to the limits of malloc() (about 2GB). The hallmark of JudyHS is speed with scalability, but memory efficiency is excellent. The speed is very competitive with the best hashing methods. The memory efficiency is similar to a linked list of the same Indexes and Values. JudyHS is designed to scale from 0 to billions of Indexes. A JudyHS array is allocated with a NULL pointer Pvoid_t PJHSArray = (Pvoid_t) NULL; Because the macro forms of the API have a simpler error handling interface than the equivalent functions, they are the preferred way to use JudyHS. JHSI(PValue, PJHSArray, Index, Length) // JudyHSIns() Given a pointer to a JudyHS array (PJHSArray), insert an Index string of length: Length and a Value into the JudyHS array: PJHSArray. If the Index is successfully inserted, the Value is initialized to 0. If the Index was already present, the Value is not modified. Return PValue pointing to Value. Your program should use this pointer to read or modify the Value, for example: Value = *PValue; *PValue = 1234; Note: JHSI() and JHSD can reorganize the JudyHS array. Therefore, pointers returned from previous JudyHS calls become invalid and must be re-acquired (using JHSG()). JHSD(Rc_int, PJHSArray, Index, Length) // JudyHSDel() Given a pointer to a JudyHS array (PJHSArray), delete the specified Index along with the Value from the JudyHS array. Return Rc_int set to 1 if successfully removed from the array. Return Rc_int set to 0 if Index was not present. JHSG(PValue, PJHSArray, Index, Length) // JudyHSGet() Given a pointer to a JudyHS array (PJHSArray), find Value associated with Index. Return PValue pointing to Index's Value. Return PValue set to NULL if the Index was not present. JHSFA(Rc_word, PJHSArray) // JudyHSFreeArray() Given a pointer to a JudyHS array (PJHSArray), free the entire array. Return Rc_word set to the number of bytes freed and PJHSArray set to NULL. ERRORS
: See: Judy_3.htm#ERRORS EXAMPLES
Show how to program with the JudyHS macros. This program will print duplicate lines and their line number from stdin. #include <unistd.h> #include <stdio.h> #include <string.h> #include <Judy.h> // Compiled: // cc -O PrintDupLines.c -lJudy -o PrintDupLines #define MAXLINE 1000000 /* max fgets length of line */ uint8_t Index[MAXLINE]; // string to check int // Usage: PrintDupLines < file main() { Pvoid_t PJArray = (PWord_t)NULL; // Judy array. PWord_t PValue; // Judy array element pointer. Word_t Bytes; // size of JudyHS array. Word_t LineNumb = 0; // current line number Word_t Dups = 0; // number of duplicate lines while (fgets(Index, MAXLINE, stdin) != (char *)NULL) { LineNumb++; // line number // store string into array JHSI(PValue, PJArray, Index, strlen(Index)); if (PValue == PJERR) // See ERRORS section { fprintf(stderr, "Out of memory -- exit "); exit(1); } if (*PValue == 0) // check if duplicate { Dups++; printf("Duplicate lines %lu:%lu:%s", *PValue, LineNumb, Index); } else { *PValue = LineNumb; // store Line number } } printf("%lu Duplicates, free JudyHS array of %lu Lines ", Dups, LineNumb - Dups); JHSFA(Bytes, PJArray); // free JudyHS array printf("JudyHSFreeArray() free'ed %lu bytes of memory ", Bytes); return (0); } AUTHOR
JudyHS was invented and implemented by Doug Baskins after retiring from Hewlett-Packard. SEE ALSO
Judy(3), Judy1(3), JudyL(3), JudySL(3), malloc(), the Judy website, http://judy.sourceforge.net, for further information and Application Notes. JudyHS(3)
All times are GMT -4. The time now is 09:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy